Android地图API V2变化MyLocation图标
我想取代Android地图V2采用了我的位置(小蓝点/箭头)与我自己的形象的默认图标。我已经创建了自己的瓷砖提供商
带来的几张地图这是predominantly蓝色,因此默认我的位置的图标是很难看到的。 previously我刚才覆盖的 MyLocationOverlay
,但似乎并没有成为一个在新的API绘制方法。任何帮助将是巨大的!
I would like to replace the default icon that Android Maps V2 uses for 'My Location' (The little blue dot/arrow) with my own image. I've created my own tile provider
that brings in a few maps which are predominantly blue and as such the default My Location icon is very hard to see. Previously I would have just overridden the draw method of the MyLocationOverlay
, but there doesn't seem to be one in the new api. Any help would be great!
编辑:我还需要图标,能够旋转,同样的方式,箭头就取决于哪种方式,你都面临。所以我不能只是使用普通的标记
:(基本上我只需要创建为箭头的自定义图像。
I also need the icon to be able to rotate, the same way that the arrow does depending on which way you are facing. So i can't just use a normal marker
:( Basically I just need to create a custom image for that arrow..
更新大家好,更新到谷歌现在可以打平的标记和标记旋转而这正是我需要的。
Update Hi All, the update to Google play now allows flat markers and marker rotation which is exactly what I needed.
最近更新谷歌播放服务,现在可以使用'平'标记和旋转它们而这正是我需要的。下面是我实现它的方式一个简单的版本。有可能是一个公平一点我可以做的优化和调整动画,但它的工作的时刻。任何反馈意见是值得欢迎的。
The latest update to Google Play Services now allows you to use 'Flat' Markers and rotate them which is exactly what I needed. Here is a simple version of the way I implemented it. There is probably a fair bit I can do to optimize and tweak the animation, but it does the job for the moment. Any feedback is welcome.
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);
}
}
});
}