Google Maps: Current Location Marker (Period updates for GMaps)

后端 未结 2 811
梦谈多话
梦谈多话 2020-12-18 16:31

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

相关标签:
2条回答
  • 2020-12-18 17:10
    mMap.setMyLocationEnabled(true);
    

    this is simple trick for blue marker of current location and did the trick for me.

    0 讨论(0)
  • 2020-12-18 17:12

    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);
    }
    
    0 讨论(0)
提交回复
热议问题