【发布时间】:2013-04-19 11:12:31
【问题描述】:
使用 Google Maps Android API v2 在地图上添加一些标记时,标记未设置到正确的位置并在缩放时移动。
在放大时,它们会更接近正确的位置,就好像它们被与缩放相关的因素平移了一样。
怎么了?
放大示例:
片段
public class CenterMapFragment extends Fragment {
private GoogleMap mMap;
private List<Center> mCenterList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.center_map_fragment, container, false);
}
@Override
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
mMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
mCenterList = MyApplication.dbHelper.getAllCenter();
for(Center center : mCenterList){
mMap.addMarker(new MarkerOptions().position(new LatLng(center.lat, center.lng)).icon(BitmapDescriptorFactory
.fromResource(R.drawable.myicon)));
}
}
}
}
布局
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
【问题讨论】:
-
现在,当您添加屏幕截图时,我可以说问题肯定出在锚点
-
你的图标上有空白吗?
-
同样的问题有解决办法吗?
-
@UsmanGhauri 是的,已接受。
-
@jul :对我不起作用。我尝试添加锚点它仍然定位到稍微偏离。我点击并试用了这些,但仍然没有运气。我使用 svg 图标作为定位销
标签: android google-maps-markers google-maps-android-api-2