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
var request = {
origin: "33.661565,73.041330",
destination: "33.662502,73.044061",
travelMode: google.maps.TravelMode.DRIVING
};
This works fine
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With