Google地图:当前位置标记(GMaps的周期更新) [英] Google Maps: Current Location Marker (Period updates for GMaps)
问题描述
下面这行代码在我的地图上实现了一个按钮,它可以找到我当前的位置并在其上放置一个蓝色点/标记不会收到定期更新)
mMap.setMyLocationEnabled(true);
我应该在我的 onLocationChanged()
事件,以便使用 new lat和long
蓝点和精度圆圈由地图自动管理,您无法更新或更改其符号系统。实际上,它使用它自己的LocationProvider自动进行管理,因此它获得了最佳的位置分辨率(您不需要编写代码来更新它,只需使用 如果你想嘲笑它的行为,你可以写这样的东西(你应该禁用我的位置层做 So I've been able to get periodic updates of my current location through the developer android page, making your app location aware. Now, whenever my location changes, I am able to get the latitude and longitude of that location. However, who do i implement this with Google Maps? This line below implements a button on my map that finds my current location and places a blue dot/marker on it (does not receive periodic updates) mMap.setMyLocationEnabled(true); What should I put in my The blue dot and the precision circle are automatically managed by the map and you can't update it or change it's symbology. In fact, it's managed automatically using it's own LocationProvider so it gets the best location resolution available (you don't need to write code to update it, just enable it using If you want to mock it's behaviour you can write something like this (you should disable the my location layer doing
这篇关于Google地图:当前位置标记(GMaps的周期更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! mMap.setMyLocationEnabled(true)启用它;
私人BitmapDescriptor markerDescriptor;
private int accuracyStrokeColor = Color.argb(255,130,182,228);
private int accuracyFillColor = Color.argb(100,130,182,228);
私人标记位置标记;
私人圆形精度圆形;
@Override
protected void onCreate(Bundle savedInstanceState){
// ...
markerDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.yourmarkericon );
}
@Override
public void onLocationChanged(Location location){
double latitude = location.getLatitude();
double longitude = location.getLongitude();
float accuracy = location.getAccuracy();
if(positionMarker!= null){
positionMarker.remove();
}
最终MarkerOptions positionMarkerOptions = new MarkerOptions()
.position(new LatLng(latitude,longitude))
.icon(markerDescriptor)
.anchor(0.5f ,0.5f);
positionMarker = mMap.addMarker(positionMarkerOptions);
if(accuracyCircle!= null){
accuracyCircle.remove();
}
final CircleOptions accuracyCircleOptions = new CircleOptions()
.center(new LatLng(latitude,longitude))
.radius(accuracy)
.fillColor(accuracyFillColor)
.strokeColor(accuracyStrokeColor)
.strokeWidth(2.0f);
accuracyCircle = mMap.addCircle(accuracyCircleOptions);
}
onLocationChanged()
event in order for the blue dot to be updated with the new lat and long?mMap.setMyLocationEnabled(true);
).mMap.setMyLocationEnabled(false);
):private BitmapDescriptor markerDescriptor;
private int accuracyStrokeColor = Color.argb(255, 130, 182, 228);
private int accuracyFillColor = Color.argb(100, 130, 182, 228);
private Marker positionMarker;
private Circle accuracyCircle;
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
markerDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.yourmarkericon);
}
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
float accuracy = location.getAccuracy();
if (positionMarker != null) {
positionMarker.remove();
}
final MarkerOptions positionMarkerOptions = new MarkerOptions()
.position(new LatLng(latitude, longitude))
.icon(markerDescriptor)
.anchor(0.5f, 0.5f);
positionMarker = mMap.addMarker(positionMarkerOptions);
if (accuracyCircle != null) {
accuracyCircle.remove();
}
final CircleOptions accuracyCircleOptions = new CircleOptions()
.center(new LatLng(latitude, longitude))
.radius(accuracy)
.fillColor(accuracyFillColor)
.strokeColor(accuracyStrokeColor)
.strokeWidth(2.0f);
accuracyCircle = mMap.addCircle(accuracyCircleOptions);
}