Android: I want to obtain location using GPS in the background for use with a directions tool in my app, how?

房东的猫 提交于 2019-12-08 13:42:30

问题


One of the activities for my company's app has a directions utility that allows the user to input their postcode, choose one of our offices, and Maps will route from the given postcode to one of our offices.

Leaving the postcode field blank results in Maps defaulting to 'your location', however you need to click 'Go' in the Maps app for it to work, while providing a postcode will automatically do the routing without having to make that extra click.

This is a small but necessary thing that needs to be solved for ease of use purposes.

I understand that i will need to use locationManager etc, however i am unsure how to use it properly. A lot of the tutorials i've seen implement a full mapView, however i am simply wanting to obtain the users location via GPS, and geocode that into a postcode all in the background so the user doesn't actually see anything.

I'm sure it's possible, but what do i need to do?

Thanks.


回答1:


Here is the overview of location services in Android. Here is the LocationManager class at the heart of location services in Android.

Unfortunately, it does not appear that Android ships with any examples of the location API, which is somewhat surprising.

You can download the source code from this book -- look for the Internet/Weather and Service/WeatherPlus demos, each of which uses LocationManager. Or, you can download the source from this another book -- look for the 23-Location tutorial for some examples of using LocationManager.

This is another tutorial.




回答2:


And this is the one I used when doing the same: Obtaining User Location



来源:https://stackoverflow.com/questions/5274125/android-i-want-to-obtain-location-using-gps-in-the-background-for-use-with-a-di

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