我想用我自己的图片替换安卓地图V2在“我的位置”中使用的默认图标。我已经创建了自己的瓦片提供商,它引入了一些以蓝色为主的地图,因此默认的我的位置图标,小蓝色箭头,很难看到。
以前,我只会覆盖MyLocationOverlay
的draw方法,但新的API中似乎没有这样的方法。
我还需要图标能够旋转,同样的方式,箭头做取决于你面对的方向。所以我不能只用普通的记号笔。基本上,我只需要为该箭头创建一个自定义图像。
发布于 2013-10-29 14:50:42
Google Play服务的最新更新现在允许你使用“平面”标记并旋转它们,这正是我所需要的。下面是我实现它的方式的一个简单版本。可能有一些我可以做的来优化和调整动画,但它目前已经完成了工作。欢迎任何反馈。
Marker mPositionMarker;
GoogleMap mMap;
@Override
public void onLocationChanged(Location location) {
if (location == null)
return;
if (mPositionMarker == null) {
mPositionMarker = mMap.addMarker(new MarkerOptions()
.flat(true)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.positionIndicator))
.anchor(0.5f, 0.5f)
.position(
new LatLng(location.getLatitude(), location
.getLongitude())));
}
animateMarker(mPositionMarker, location); // Helper method for smooth
// animation
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location
.getLatitude(), location.getLongitude())));
}
public void animateMarker(final Marker marker, final Location location) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
final LatLng startLatLng = marker.getPosition();
final double startRotation = marker.getRotation();
final long duration = 500;
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed
/ duration);
double lng = t * location.getLongitude() + (1 - t)
* startLatLng.longitude;
double lat = t * location.getLatitude() + (1 - t)
* startLatLng.latitude;
float rotation = (float) (t * location.getBearing() + (1 - t)
* startRotation);
marker.setPosition(new LatLng(lat, lng));
marker.setRotation(rotation);
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
}
}
});
}
发布于 2013-02-12 14:07:20
我的简单解决方法是禁用谷歌地图的“我的位置”
然后使用我的图标在地图上创建ImageView,然后使用捕获ImageView
onClick和getMyLocation,onClick中的animateCamera
this.mGoogleMap.getUiSettings().setMyLocationButtonEnabled(false);
this.mGoogleMap.setMyLocationEnabled(true);
。
@Override
public void onClick(final View v) {
Location location = this.mGoogleMap.getMyLocation();
if (location != null) {
LatLng target = new LatLng(location.getLatitude(), location.getLongitude());
CameraPosition position = this.mGoogleMap.getCameraPosition();
Builder builder = new CameraPosition.Builder();
builder.zoom(15);
builder.target(target);
this.mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(builder.build()));
}
}
发布于 2013-05-31 20:12:06
从3.1.36开始,你不能改变图标(我觉得它在未来会改变,但是看看API v2改进的实现速度,不会在圣诞节之前)。
但是,您现在可以使用标记,因为它具有setIcon
功能。
基本上你必须忘记GoogleMap.setMyLocationEnabled
,因为它总是出现在上面。相反,您将创建自己LocationClient
,并使用Location
中的lat、long和bearing来更新Marker
。此外,添加一个Circle
并使用accuracy来获得类似于默认myLocation可视化的效果。
https://stackoverflow.com/questions/14826345
复制相似问题