我试图弄清楚为什么当我缩小地图视图时我的图标会出现在海洋上,但是当我放大点时是正确的。
这是我的代码:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview1);
mapView.setBuiltInZoomControls(true);
MapController mapController = mapView.getController();
//set up test points
point = new GeoPoint(25982160, -80358564);
showAnimatedMarker(point, "true");
point = new GeoPoint(34023084, -84781697);
showAnimatedMarker(point, "Test");
point = new GeoPoint(40759508, -73987061);
showAnimatedMarker(point, "Yo YO YO");
point = new GeoPoint(34152852, -118336107);
showAnimatedMarker(point, "Boom shakalaka");
point = new GeoPoint(-23564595, -46652759);
showAnimatedMarker(point, "Testing having a real long name");
mapController.setZoom(4);
mapController.animateTo(point);
}
public void showAnimatedMarker(GeoPoint point, String locationName)
{
//animate the marker
RelativeLayout v = (RelativeLayout) View.inflate(this, R.layout.markerlayout, null);
final ImageView marker = (ImageView) v.findViewById(R.id.marker);
final TextView markerText = (TextView) v.findViewById(R.id.markerText);
final String locName = locationName;
marker.post(new Runnable() {
@Override
public void run() {
markerText.setText(locName);
AnimationDrawable markerImage = (AnimationDrawable)marker.getDrawable();
markerImage.start();
}
});
mapView.addView(v, 0, new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, point, MapView.LayoutParams.BOTTOM_CENTER));
}
这是 2 张图片,显示了我的意思,1 张被缩小,1 张被放大到加利福尼亚的位置。
任何帮助将不胜感激。
编辑:
这是我更新的代码(我没有包含 myOverlays 类,因为它正是 Frohnzie 发布的)
MapController mapController = mapView.getController();
MyOverlay testOverlay;
//set up test points
point = new GeoPoint(25982160, -80358564);
//showAnimatedMarker(point, "true");
testOverlay = new MyOverlay(this, mapView, point);
mapOverlays.add(testOverlay);
point = new GeoPoint(34023084, -84781697);
//showAnimatedMarker(point, "Test");
testOverlay = new MyOverlay(this, mapView, point);
mapOverlays.add(testOverlay);
point = new GeoPoint(40759508, -73987061);
//showAnimatedMarker(point, "Yo YO YO");
testOverlay = new MyOverlay(this, mapView, point);
mapOverlays.add(testOverlay);
point = new GeoPoint(34152852, -118336107);
//showAnimatedMarker(point, "Boom shakalaka");
testOverlay = new MyOverlay(this, mapView, point);
mapOverlays.add(testOverlay);
point = new GeoPoint(-23564595, -46652759);
//showAnimatedMarker(point, "Testing having a real long name");
testOverlay = new MyOverlay(this, mapView, point);
mapOverlays.add(testOverlay);
mapController.setZoom(4);
mapController.animateTo(point);
mapView.invalidate();
}