对于我们的应用程序,我们需要以半径显示当前用户的位置。但是当我启用map.setMyLocationEnabled(true);
时,我们已经注意到,精度半径在很大范围内变化(例如从10米到50米,然后是15米等),这可能会让我们的用户感到困惑。我们决定在标记周围修正精度圆的半径,以赋予它不同的含义。
除了创建自己的标记外,还有办法修复精度半径吗?我不想创建自己的标记,因为我认为我的认识会比谷歌更糟糕。
提前致谢。
答案 0 :(得分: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)