Android: access saved google locations programmatically

笑着哭i 提交于 2019-12-08 17:28:32

问题


Google maps allows the possibility of saving favourite locations for ease of access later... see here.

In Android, where a location is required to be entered, it would be neat if there were an API to enable the user to choose from their already-saved favourite locations, e.g. via a picker dialog or something along those lines.

I can't find such an API... is there? The closest I've found is this and this, but these don't seem to allow picking from your stored locations.


回答1:


There really isn't a way to do this, but you could create your own method to do it. You could have an ImageButton with a star (or anything that symbolizes 'save'). Use SharedPreferences to save the latitudes and longitudes that the users have entered, and then every time the application is loaded up, you could check to see if there are some values in the SharedPreferences. If there are, you could use a ListView to show all the saved locations, and then when one is clicked, return to the parent activity with the Location. Finally, use the Location to orient the map correctly.




回答2:


Google/Android doesn't provide any public API to access the starred/frequent locations of a user and that data is only shared amongst the Google apps.

As this answer shows it might be possible to fetch location data via the Google Plus and Google Identity platform APIs

Alternatively (or in addition to), using Google's Plus Platform / Google Identity Platform, if you have an authenticated user, you can make an API call as described here (with examples) to get any of the specified fields for the current user (including currentLocation, organizations (including work) with addresses, if the user provided them).

Take a look at this link.



来源:https://stackoverflow.com/questions/37157108/android-access-saved-google-locations-programmatically

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