2016-05-17 36 views
0

對於我們的應用程序,我們需要用某個半徑顯示當前用戶的位置。但是當我啓用map.setMyLocationEnabled(true);時,我們已經注意到,精度半徑在非常大的範圍內變化(例如從10米到50米,然後是15米等),這可能會讓我們的用戶感到困惑。我們已經決定修復標記周圍的精度圓的半徑,使其具有不同的含義。有沒有辦法在Google地圖上修正標記的精度半徑?

除了創建自己的標記之外,是否有辦法修復精度半徑?我不想創建自己的標記,因爲我認爲我的認識會比谷歌更糟糕。

在此先感謝。

+1

因爲我認爲答案是沒有 –

+0

你不能改變我的位置層,但你可以cr吃掉你自己的實現。看看http://stackoverflow.com/questions/33411112/change-custom-current-location-indicator-in-google-map-v2/33417474#33417474 – antonio

回答

1

使用My Location layer,您無法更改當前位置的符號系統(圖標)。

作爲解決方法,您可以使用Location Updates並在地圖上繪製位置來實現此功能。

要做到這一點,你可以用這個實現的LocationListener繪製當前位置和精度:

import android.graphics.Color; 
import android.location.Location; 
import android.location.LocationListener; 
import android.os.Bundle; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.model.BitmapDescriptor; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.Circle; 
import com.google.android.gms.maps.model.CircleOptions; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MyLocationLayer implements LocationListener { 
    private GoogleMap map; 

    private BitmapDescriptor markerDescriptor; 
    private boolean drawAccuracy = true; 
    private int accuracyStrokeColor = Color.argb(255, 130, 182, 228); 
    private int accuracyFillColor = Color.argb(100, 130, 182, 228); 

    private Marker positionMarker; 
    private Circle accuracyCircle; 

    public MyLocationLayer(GoogleMap map, int markerResource) { 
     this.map = map; 

     markerDescriptor = BitmapDescriptorFactory.fromResource(markerResource); 
    } 

    public void setDrawAccuracy(boolean drawAccuracy) { 
     this.drawAccuracy = drawAccuracy; 
    } 

    public void setAccuracyStrokeColor(int color) { 
     this.accuracyStrokeColor = color; 
    } 

    public void setAccuracyFillColor(int color) { 
     this.accuracyFillColor = color; 
    } 

    @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 = map.addMarker(positionMarkerOptions); 

     if (accuracyCircle != null) { 
      accuracyCircle.remove(); 
     } 
     if (drawAccuracy) { 
      final CircleOptions accuracyCircleOptions = new CircleOptions() 
        .center(new LatLng(latitude, longitude)) 
        .radius(accuracy) 
        .fillColor(accuracyFillColor) 
        .strokeColor(accuracyStrokeColor) 
        .strokeWidth(2.0f); 
      accuracyCircle = map.addCircle(accuracyCircleOptions); 
     } 
    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 

    } 

    @Override 
    public void onProviderEnabled(String provider) { 

    } 

    @Override 
    public void onProviderDisabled(String provider) { 

    } 
} 

改進製成可以旋轉基於方向的標記

運動使用public MarkerOptions rotation (float rotation)https://developers.google.com/android/reference/com/google/android/gms/maps/model/MarkerOptions.html#rotation(float)

+0

謝謝!這是非常有用的答案。 –

相關問題