Geocoding API vs Geocoder

吃可爱长大的小学妹 提交于 2019-12-10 10:55:36

问题


In my application I need to use the geocoding, but I am not quite clear which method to use. Until yesterday I added the parameters to the URL maps.googleapis.com/maps/api/geocode/json?address=myparameter&sensor=false, but Google blocked my requests for a day, making the application crash because it did not return any results from the request for geocoding.

Now I am using the Geocoder class that does the same thing and also I have seen that you can create and use an API key for Geocoding.
Which method do you recommend to use? What is the difference between the two methods, apart from the limitations of the requests?


回答1:


If you need to use a map in your app, you should use the API called: Google Maps Android API v2.

If you need to manage geocoded data (address to lat/lng or viceversa) then enable Geocoding API and start using the class Geocoder.

For example (lat/lng to address):

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(gps.getLatitude(),  gps.getLongitude(), 1); 



回答2:


Users of free API have following limits:

  • 2,500 requests per 24 hour period.
  • 5 requests per second.

You can include API key in web-request also like:

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=API_KEY

Not sure about android Geocoder class, maybe someone else can help you out in that matter. But i assume same limits would apply.



来源:https://stackoverflow.com/questions/28858426/geocoding-api-vs-geocoder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!