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

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

问题描述

因此,我已经能够通过开发者 android 页面定期更新我的当前位置,从而了解您的应用位置.现在,每当我的位置发生变化时,我都能获得该位置的纬度和经度.但是,我该由谁使用 Google 地图来实现这一点?

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);

mMap.setMyLocationEnabled(true);

我应该在我的 onLocationChanged() 事件中放入什么,以便使用 纬度和经度更新蓝点?

What should I put in my onLocationChanged() event in order for the blue dot to be updated with the new lat and long?

推荐答案

蓝点和精密圆由地图自动管理,您无法更新或更改其符号系统.事实上,它是使用自己的 LocationProvider 自动管理的,因此它可以获得可用的最佳位置分辨率(您不需要编写代码来更新它,只需使用 mMap.setMyLocationEnabled(true); 启用它).

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);).

如果你想模拟它的行为,你可以写这样的东西(你应该禁用我的位置层做mMap.setMyLocationEnabled(false);):

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 地图:当前位置标记(GMap 的期间更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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