Android current location marker ID (name)

喜夏-厌秋 提交于 2019-12-12 05:44:19

问题


I am pretty much a novice at Android development, so please feel free to describe in very simple terms any advice you may give in response to my query.

I would like my application to start by displaying an Activity zoomed out to an extent that shows both my current location and that of a marker that I have placed on a map some distance from me.

I have successfully placed and displayed the remote marker the on the map and have found this class: LatLngBounds.Builder, which allows me to determine the bounds of all locations I am interested in, by supplying it the locations via its include method.

I obviously know the LatLng of my remote marker, but rather than going through the rigmarole of getting my current location using Google Play services and the location services API was wondering if, as my location has already been determined and is being displayed as the standard Google small blue circle, by virtue of me having set map.setMyLocationEnabled(true), whether my code has access to this ‘marker’. If it has, and I somehow know its ID, then could I not simply determine my location from [currentLocationBlueCircleMarker].getPosition()?

Thank you


回答1:


There used to be a way to get a Location from a GoogleMap object, but it has been deprecated:

com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener

This interface is deprecated. use com.google.android.gms.location.FusedLocationProviderApi instead. FusedLocationProviderApi provides improved location finding and power usage and is used by the "My Location" blue dot. See the MyLocationDemoActivity in the sample applications folder for example example code, or the Location Developer Guide.

So, you will need to use other means to get the current Location, though it's quite simple to get the current location using the FusedLocationProviderApi from Google Play Services.

For a complete example (targeting api-23 and up) see here: https://stackoverflow.com/a/34582595/4409409

For a complete example (targeting api-22 and down) see here: https://stackoverflow.com/a/30255219/4409409



来源:https://stackoverflow.com/questions/37281382/android-current-location-marker-id-name

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