Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

request

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

I get the proper response, but instead of passing Station name I want to pass the latitude-longitude of the stations.

A documentation can be found at Here

How can I pass latitude-longitude to this service?

EDIT :

When I give the URL as - http://maps.googleapis.com/maps/api/directions/json?origin=Jackson+Av&destination=Prospect+Av&sensor=false I get the proper response, but when I give 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 response as - ZERO RESULT

like image 512
Deepu Avatar asked Dec 07 '12 13:12

Deepu


2 Answers

var request = { 
            origin: "33.661565,73.041330",
            destination: "33.662502,73.044061",
            travelMode: google.maps.TravelMode.DRIVING
};

This works fine

like image 154
Haseeb Jadoon Avatar answered Oct 29 '22 18:10

Haseeb Jadoon


You can create url to get as follow,

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);

Please check you are providing correct geoco-ordinates

like image 25
Babasaheb Avatar answered Oct 29 '22 18:10

Babasaheb