How to pass latitude-longitude to Google Maps JavaScript API v3 service?

I want to use the Google Maps JavaScript v3 API in my Java application. To do this, I create an HttpGet object with http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false .

I get the correct answer, but instead of transmitting the name of the station, I want to transmit the latitude-longitude of the stations.

The documentation can be found in here.

How can I pass latitude-longitude to this service?

EDIT:

When I specify the URL as http://maps.googleapis.com/maps/api/directions/json?origin=Jackson+Av&destination=Prospect+Av&sensor=false , I get the correct answer, but when I give the url as -

http://maps.googleapis.com/maps/api/directions/json?origin=40.81649,73.907807&destination=40.819585,-73.90177&sensor=false I get the answer as - ZERO RESULT

+8
java request
source share
4 answers

You can create a URL to get the following:

double lat1 = 40.74560; double lon1 = -73.94622000000001; double lat2 = 46.59122000000001; double lon2 = -112.004230; String url = "http://maps.googleapis.com/maps/api/directions/json?"; List<NameValuePair> params = new LinkedList<NameValuePair>(); params.add(new BasicNameValuePair("origin", lat1 + "," + lon1)); params.add(new BasicNameValuePair("destination", lat2 + "," + lon2)); params.add(new BasicNameValuePair("sensor", "false")); String paramString = URLEncodedUtils.format(params, "utf-8"); url += paramString; HttpGet get = new HttpGet(url); 

Make sure you set the correct geo-coordinates

+14
source share

Web Services Documentation Link

Just use numbers for latitude, longitude , separated by comma: for example 51,0 . Make sure there are no spaces.

http://maps.googleapis.com/maps/api/directions/json?origin=51,0&destination=51.5,-0.1&sensor=false

+8
source share

The documentation for API v3 says google.maps.LatLng or a string. For geographic locations, create and go to google.maps.LatLng; for addresses, pass the string.

 origin: LatLng | String, destination: LatLng | String, 

And in reference

 destination LatLng|string Location of destination. This can be specified as either a string to be geocoded or a LatLng. Required. origin LatLng|string Location of origin. This can be specified as either a string to be geocoded or a LatLng. Required. 

and for waypoint :

 location LatLng|string Waypoint location. Can be an address string or LatLng. Optional. 
+2
source share
 var request = { origin: "33.661565,73.041330", destination: "33.662502,73.044061", travelMode: google.maps.TravelMode.DRIVING }; 

It works great

+1
source share

All Articles