标记和折线的位置不匹配:Android的谷歌地图API第2版 [英] Google Maps API v2 for Android: Marker and Polyline position mismatch
问题描述
我想画一些标记和折线在同一张地图这样
I'm trying to draw some markers and a polyline in the same map this way
MarkerOptions options = new MarkerOptions();
Marker marker;
PolylineOptions polyLineOptions = new PolylineOptions();
polyLineOptions.color(context.getResources().getColor(R.color.mm_red));
if (route != null) {
for(Entry entry : route.getEntries().getEntryList()){
LatLng pos = new LatLng(entry.getGeolocation().getLatitude(), entry.getGeolocation().getLongitude());
options.position(pos);
polyLineOptions.add(pos);
marker = mMap.addMarker(options.icon(BitmapDescriptorFactory.fromResource(R.drawable.im_map_marker_main_num)));
marker.setVisible(true);
}
Polyline polyline = mMap.addPolyline(polyLineOptions);
polyline.setVisible(true);
}
不过,在这里你可以看到结果我得到:
However, here you can see the result I get:
正如你所看到的,即使我通过同样的经纬度
位置,既的MarkerOptions
和的PolylineOptions
,存在某种偏差。
As you can see, even if I pass the same LatLng
position to both MarkerOptions
and PolylineOptions
, there is some kind of offset.
作为额外的信息,我得到这个行为的的Nexus 7。
As extra information, I get this behaviour in a Nexus 7.
感谢您
编辑:标记图标的针位置是默认的,所以它的底侧的中心
The marker icon's pin location is the default one, so the center of the bottom side of it
编辑:不创建位图的问题。如果我使用 canvas.drawColor
,这是我得到的(不同的大小,因为现在我用的Nexus 10)
Not bitmap creation problem. If I use canvas.drawColor
, this is what I get (different size, because now I'm with a Nexus 10)
推荐答案
这里的问题是,默认情况下的针位置标记
是在底部中心图像
The problem here is that by default, the pin location of the Marker
is at the bottom center of the image.
您将有乱动<一个href=\"https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/MarkerOptions#anchor%28float,%20float%29\"相对=nofollow> 锚(浮动,浮动)
和/或确保锋利的刀刃在底部中央的最后像素(没有透明像素如下图)。
You will have to fiddle with anchor(float, float)
and / or make sure the sharp edge is the last pixel on the bottom center (with no transparent pixels below).
这篇关于标记和折线的位置不匹配:Android的谷歌地图API第2版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!