简体   繁体   中英

Android direction in Google Maps with latitude and longitude

I want send my origin point and destination point to Google for direction. When I use name for origin and destination it's true and returns true JSON information, but when I send latitude and longitude for origin and destination it doesn't work.

It's ok whit this URL: https://maps.googleapis.com/maps/api/directions/json?origin=tehran&destination=shiraz&key=AIzaSyBvR07aFM-1ddGVgt392lRnUge3weT6nUY

But it doesn't work with this: https://maps.googleapis.com/maps/api/directions/json?origin=32,52&destination=34,54&key=AIzaSyBvR07aFM-1ddGVgt392lRnUge3weT6nUY

I think the problem is the coordinates you're using - they look like they're not accessible via roads. Make sure that you're not casting the latitude or longitude to ints, you need the decimal-point precision.

Converting Tehran and Shiraz to latlngs, I get the following URL which works correctly:

https://maps.googleapis.com/maps/api/directions/json?origin=35.6887931,51.3891646&destination=29.5916593,52.583701&key=<api key here>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM