Android当前位置标记ID(名称) [英] Android current location marker ID (name)

查看:140
本文介绍了Android当前位置标记ID(名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎是Android开发的新手,所以请随时以非常简单的方式描述您为回应我的查询而提供的任何建议.

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.

我已成功在地图上放置并显示了远程标记,并找到了此类:LatLngBounds.Builder,该类使我能够通过其include方法提供位置信息,从而确定我感兴趣的所有位置的范围

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.

我显然知道我的远程标记的LatLng,但没有经历使用Google Play服务获取我的当前位置的繁琐操作,而位置服务API却想知道,因为我的位置已经确定并显示为由于我设置了map.setMyLocationEnabled(true),因此我的代码是否可以访问此标记",因此是标准的Google小蓝色圆圈.如果有,而且我以某种方式知道它的ID,那么我是否不能简单地从[currentLocationBlueCircleMarker] .getPosition()确定我的位置?

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()?

谢谢

推荐答案

曾经有一种方法从GoogleMap对象获取位置,但已弃用:

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

不推荐使用此接口.使用 改为使用com.google.android.gms.location.FusedLocationProviderApi. FusedLocationProviderApi提供了改进的位置查找和功能 用法,并由我的位置"蓝色圆点使用.见 例如,示例应用程序文件夹中的MyLocationDemoActivity 示例代码或《位置开发人员指南》.

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.

因此,尽管使用Google Play服务中的FusedLocationProviderApi获取当前位置非常简单,但是您将需要使用其他方法来获取当前位置.

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.

有关完整示例(针对api-23及更高版本)的信息,请参见此处: https://stackoverflow.com/a/34582595/4409409

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

有关完整示例(针对api-22及更低版本)的信息,请参见此处: https://stackoverflow.com/a/30255219/4409409

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

这篇关于Android当前位置标记ID(名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆