Google Maps (javascript API): get GPS coordinates from address - javascript

I need to calculate the distance between two addresses and I don't need a map view or anything graphical.
I simply want the user to type in the address (end location is defined by myself) and let the javascript calculate the distance between the two points.
However I don't find a way to send an address string and get the GPS-coordinates from it using the Google Maps API.
(I really only need the two GPS points, the distance calculation is trivial.)

What you are trying to do is called geocoding. It is possible with the Maps API. See the Geocoding section for more details. This is the basic idea:
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
"address": inputAddress
}, function(results) {
console.log(results[0].geometry.location); //LatLng
});
However, you are limited to 2500 geocoding requests a day, and what you are trying to do is against the terms of use:
Note: the Geocoding API may only be used in conjunction with a Google
map; geocoding results without displaying them on a map is prohibited.

This page describes a Google JSON service that you can extract gps coordinates from. I think this would also be under the "No Use of Content without a Google Map" in the TOS.

This is possible. See below link
http://briancray.com/posts/how-to-calculate-the-distance-between-two-addresses-with-javascript-and-google-maps-api

Related

I Want to convert lat and lat to get the name of place marker in website?

Iam Using this library https://github.com/wimagguc/jquery-latitude-longitude-picker-gmaps
to make map with marker
and use in the backend laravel
i want to get the name of place where the marker located on it
how can i do it ?!
in the database i am saved the lat and lng
any way to get the name of place ???
enter image description here
Reverse Geocoding in Geocoding API would be able to help you convert latlng coordinates into addresses. You may refer to this documentation: https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding
Here is a sample HTTP request: https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
However, kindly note that, and as mentioned in the doc, Reverse geocoding is an estimate. The geocoder will attempt to find the closest addressable location within a certain tolerance. If no match is found, the geocoder will return zero results.
I hope this helps!

Google Maps API Autocomplete doesn't return same result as a Google Maps Search

No result is returned when using the Google Maps API v3. Autocomplete, however when doing a Google Maps Search for the same address will return a result.
Why is this and how can this be resolved?
Example.
Works:
Google maps, finds the address:
https://www.google.co.uk/maps?q=1+Oakland+Terrace,+New+Edlington,+Doncaster+DN12+1AA
Fails:
Step 1. Use the example of the Maps API Autocomplete. https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
Step 2. Start typing or paste in the address:
1 Oakland Terrace, New Edlington, Doncaster DN12 1AA.
No address is found.
The Google Places API often returns results similar to maps.google.com, but they're not the exact same. I'm unable to reproduce any suggestions for the start of this address using maps.google.com, which matches the experience you're seeing in the Autocomplete API.
That said, this specific address appears to work correctly using the Geocoding API and the Place Text Search API. The Places API has information for that address, it's just not autocompleting. I would recommend designing your application so that if you have a full-looking address and an autocomplete request fails you fall back to a regular Places API text search or geocoding call.

Getting geolocation from IP address

I need to track user details, for that client's location and IP address is needed.
I got IP address from
$this->input->ip_address();
in codiigniter. Now the problem is how can i make their location in google map by using their respective IP address
just use ipinfo.io at
http://ipinfo.io/
it uses a location api that we can post ip address and it will returns the location details as json:
we can able to display the loacation on map with the langitude and longitude details from json response to google Maps API.
Here is the code i used:
this script creates a Google Map instance with lattitude & longitude from json response:
jQuery(document).ready(function(){
jQuery.get("http://ipinfo.io/202.88.237.138", function (response)
{
var lats = response.loc.split(',')[0];
var lngs = response.loc.split(',')[1];
map = new GMaps({
el: '#map',
lat: lats, //latitude
lng: lngs //longitude
});
}, "jsonp");
});
and the map will displayed on:
<div style="border:1px solid red; height:745px;" id="map"></div>
Google Maps API gmaps.js is needed to run this..
As a viable (although often less accurate) alternative, the HTML5 spec includes Geolocation. As HTML 5 becomes more and more prevalent I think we can expect to see this become standard in the future. It also does not require the use of external web services or libraries. Everything you need to geolocate is built right into the clients browser.
I believe the primary method used is IP address as specified.
The Google Maps API will do the work of finding location using geoip for you. If the user is on a mobile device or has a more accurate way of locating themselves (like a GPS), it'll use that instead.
Here's a good starting point:
https://google-developers.appspot.com/maps/documentation/javascript/examples/map-geolocation
If you absolutely need to fetch location from IP only, there are third-party tools that you can scrape to get this information. You should make sure you have permission beforehand if you're using this in a larger project.
freegeoip.net provides a public HTTP API to search the geolocation of IP addresses. It uses a database of IP addresses that are associated to cities along with other relevant information like time zone, latitude and longitude.
You're allowed up to 15,000 queries per hour.
If you need more than that, you can run the freegeoip as a web server on your own infrastructure. See: freegeoip on github

make multiple Markers google map by address or pincode

i want to make multiple Markers google map by address or pincode like
i just add address or pincode in array and i will made multiple marker google map
for example
var address = new Array('Canada','Newyourk')
or may be pincode
var address = new Array('123456','654321')
my basic is html and javascript
That's done using Geocoding service of the API. More on this topis here: https://developers.google.com/maps/documentation/javascript/geocoding and here: https://developers.google.com/maps/faq#geocoder_exists.
I also advice you to read the whole API documentation. It's one the best API documentations out there with lots of useful examples and guides.

Destination value with DirectionsRenderer in Google Maps v3

Loving Google Maps API V3, but having difficulty in getting accurate driving directions and manipulating the destination address displayed when using DirectionsRenderer.
Regardless if I pass an address string or a latLng instance as the destination to DirectionsService, when I use the DirectionsRenderer to output step-by-step directions, the destination text is always the geocoded result of my original destination (i.e. the address, rather than COMPANY NAME).
Ideally, I want to pass a precise latLng destination to DirectionsService, but control the text displayed as the 'destination'.
I guess I could manually output the HTML, but part lazy, part not wanting to re-invent the wheel, would prefer to use DirectionsRenderer.
Any ideas?
You may use:
response.routes[0].legs[0].end_address="Company";
before calling
directionsDisplay.setDirections(response);

Categories