Google地图:当前位置标记(GMaps的周期更新) [英] Google Maps: Current Location Marker (Period updates for GMaps)

查看:100
本文介绍了Google地图:当前位置标记(GMaps的周期更新)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我可以通过开发人员的Android页面定期更新我的当前位置,使您的应用程序位置得到了解。现在,只要我的位置发生变化,我就可以获得该位置的经纬度。然而,我是通过谷歌地图实现这一目标的?



下面这行代码在我的地图上实现了一个按钮,它可以找到我当前的位置并在其上放置一个蓝色点/标记不会收到定期更新)

mMap.setMyLocationEnabled(true);

我应该在我的 onLocationChanged()事件,以便使用 new lat和long

更新蓝点

解决方案

蓝点和精度圆圈由地图自动管理,您无法更新或更改其符号系统。实际上,它使用它自己的LocationProvider自动进行管理,因此它获得了最佳的位置分辨率(您不需要编写代码来更新它,只需使用 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);
}


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 onLocationChanged() event in order for the blue dot to be updated with the new lat and long?

解决方案

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 mMap.setMyLocationEnabled(true);).

If you want to mock it's behaviour you can write something like this (you should disable the my location layer doing 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);
}

这篇关于Google地图:当前位置标记(GMaps的周期更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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