Location-aware geocoding on Android (just like Google Maps)

孤人 提交于 2019-12-10 23:16:21

问题


It seems that the search in the Google Maps app is location aware. For example, if I search for "Pitt St" while in Sydney, it finds the right street straight away. Clicking "Did you mean..." brings a list of other "Pitt St" close in nearby suburbs.

Is there a way to ge a similar experience in our apps? I tried the standard Geocoder, but a similar search returns "Pitt St, New York" as the first match.

  • Is there a set of options I'm missing?
  • Is there a different API we can use for this?
  • As a last resort, do you think it's reasonable to implement this manually, for example by querying the Geocoder with a max radius of 1km, 10km, 100km, and then sorting the results by distance?

Cheers

Romain


回答1:


Which function did you use? Geocoder.getFromLocationName() takes a bounding box that allows you to limit the results to a certain region, so you could get the current GPS position first and pass that in.

Alternatively, you could go through the Geocoder API which is more flexible, but also more restrictive in terms of the TOS, not to mention a lot more work to use. (I'm not sure if using it from an Android app is covered in the TOS, I haven't looked at it much).



来源:https://stackoverflow.com/questions/4653608/location-aware-geocoding-on-android-just-like-google-maps

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