How to get dynamically latitude and longitude on google maps? - google-maps

I have country and address. How can I retrieve latitude and longitude from Google Maps V3?
I will use this to load the map.
EDIT
This is my actual code, but seems that Google API return this error : W[B].bindTo=function(a,b,c,d){var c=c|...R[p](this,wf,a);this.Pb&&this.Pb(a)};
SOLUTION
remove center: location,

You can retreive this with Geocoding Requests.
You can see my last project that I used this here. See function AddMarker in gmaps3.js for a working real world example. Basically I fetch addresses from database (using AJAX) and then convert them to lat/lon to make markers on the map.

You can use their ReST-API.
http://maps.google.com/maps/api/geocode/json?address=Berlin+Germany&sensor=false
The documentation is in The Google Geocoding API. You will have to do a http request e.g. $.get in jQuery to perform the query and then parse the JSON. Other output formats include XML. There's a JavaScript geocoder on their site as well.

You need to access geocoding.
http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding
http://code.google.com/apis/maps/documentation/geocoding/index.html

Related

How to display road name in marker infowindow while displaying route in google maps?

I need road name in marker infowindow while displaying route in google maps.
I found the following options,
1. Geocoder service in Google Maps Javascript API - which will give address for the given GPS coordinate.
2. Google Maps Roads API - which will return placeIds of the path and again I need to fire another request to get the address of placeId
What will be optimal solution to retrieve the road name for a given route (array of gps coordinates)?
The Geocoding API is the appropriate API to use for converting lat/lng coordinates into textual addresses and vice-versa. It's what it's meant to be used for.
The following is an example of a reverse geocoding request:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
Hope this helps!

google maps javascript is fetching the route but not the json api

I have stumbled upon this: when I use directionsDisplay.getDirections() API to fetch and display the results, it works, but when I do it via json:
https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJR0FT51wiDogRNuVKiLn9ZLA&destination=place_id:ChIJMWaiY0YpTIYRRdGvCMg7m0g&key=MY_KEY&waypoints=via:place_id:ChIJaWS37r88DIgRu-ak1l7eXAQ
I get "status" : "ZERO_RESULTS"
I am wondering why this might be happening? Any ideas?
Remove the "via:" keyword from the waypoints to get the response.
https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJR0FT51wiDogRNuVKiLn9ZLA&destination=place_id:ChIJMWaiY0YpTIYRRdGvCMg7m0g&key=MY_KEY&waypoints=place_id:ChIJaWS37r88DIgRu-ak1l7eXAQ
From the documentation:
The via: prefix is most effective when creating routes in response to the user dragging the waypoints on the map. Doing so allows the user to see how the final route may look in real-time and helps ensure that waypoints are placed in locations that are accessible to the Google Maps Directions API.
Caution: Using the via: prefix to avoid stopovers results in directions that are very strict in their interpretation of the waypoint. This may result in severe detours on the route or ZERO_RESULTS in the response status code if the Google Maps Directions API is unable to create directions through that point.

What is the web Google URL to find the directions between 2 coordinates (lat, long)?

I am trying to open up google maps in the browser by passing it 4 points. What is the scheme to launch google maps so it inputs a start coordinate and an end coordinate?
It's not offically documented, but currently this works:
https://www.google.de/maps/dir/origin_lat,origin_lng/destination_lat,destination_lng/
e.g. Chicago to Detroit:
https://www.google.de/maps/dir/41.87,-87.62/42.33,-83.04/
You may also use addresses:
https://www.google.de/maps/dir/origin_address/destination_address/
https://www.google.de/maps/dir/Chicago/Detroit/
The URL parameters for this Google API are destination and origin, here you can use adresses or coordinates as values:
https://www.google.com/maps/embed/v1/directions?origin=sydney&destination=sydney&key=...
but be aware that for this service you need an API key. When using the javascript API you don't need an API key, at least if you don't have too much traffic.

Google Map Address from latitude and longitude

I am using google map api i am fetching dynamically latitude and longitude from my database.
I want to show address for each position can any one tell me how can id that.
or can any anyone tell how this site is fetching address for each every position.
http://www.findlatitudeandlongitude.com/find-address-from-latitude-and-longitude.php#.UTpYG1c9nwk
Fetching the associated address from a coordinates is called Reverse Geocoding
The Google Maps API provides reverse geocoding in the javascript API and as a web service.
The Google Maps service is not intended for bulk use. Your best option is to store the address in your database along with the coordinates as Reverse Geocoding is not always reliable.
You can use google map api like below
http://maps.googleapis.com/maps/api/geocode/json?latlng=34.41448,-118.93753&sensor=true
Using this api,you can get address address from key
"formatted_address" : "1271 Cliff Avenue, Fillmore, CA 93015, USA"
Whole address you can get using this api.
Hope need helpful.
I'd guess that site is using the Reverse Geocoding API provided by Google.

Get latitude / longitude / Reverse Geocoding without displaying maps

Using a website, I am trying to capture user's latitude / longitude point and based on that grab his current address.
I am able to do this using Google Maps API: geolocation and Reverse GeoCoding. But, my requirement is to get this information without displaying the map. As far as I have read, Google Maps Term of Use prohibits such thing.
Can anyone let me know if there is any other service which can serve my purpose without displaying maps or does Google Maps allow such thing? I am not sure about Bing, Yahoo.
EDIT: On page load, I need to grab user's latitude and longitude and based on that get address information. I am planning to use this address information for displaying nearby locations/places to visit. I have to achieve this without displaying any map.
Yahoo PlaceFinder does it. If you pass through the latitude and longitude in the location parameter and gflags=R, it should return address data.
You'll have to get a Yahoo APP id, but its free and pretty easy to set up.
EDIT: I see you want to do geolocation too, if you can't use google I would investigate html5 geolocation and or use freegeoip.net to geolocate by ip address.
I don't know if Im mistaken this post, but if you read this:
(viii) store or allow end users to store map imagery, map data or geocoded location information from the Yahoo! Maps APIs for any future use;
(ix) use the stand-alone geocoder for any use other than displaying Yahoo! Maps or displaying points on Yahoo! Maps;
It's mean that you can't store the information, or make use of it, without maps.
So the google api and the yahoo api need to have a map...
note- I take that lines from the terms of yahoo: http://info.yahoo.com/legal/us/yahoo/maps/mapsapi/mapsapi-2141.html
EDIT - Now I'm trying to use http://www.geonames.org/export/reverse-geocoding.html It's easy, and works fine for me. I just need the city and maybe a postal code.
I don't think Yahoo requires you to show a map and it also has a higher quota.
http://developer.yahoo.com/geo/placefinder/
There are a number of geolocation APIs - here is a really good one:
https://geoip.nekudo.com/
You merely make a GET request to
http://geoip.nekudo.com/api/{ip}/{language}/{type}
where ip, language and type are optional.
E.g. in Angular 5, using HttpClient:
this.http.get('http://geoip.nekudo.com/api/')
.subscribe(
data => { console.log('SUCCESS! Your coords are lat:', data.location.latitude, 'long:', data.location.longitude); },
error => { console.log('ERROR!', error); }
);
Also, note that the geoip service is written in PHP and open source (https://github.com/nekudo/shiny_geoip) so you can house your own implementation to reduce third party dependencies.