在这里,我可以获取并显示用户在地图上的当前位置,我可以检索 Google Places json 数据并将其解析为数组。问题是,虽然显示了当前位置叠加层,但直到我将屏幕从纵向旋转到横向之后,才会出现额外的叠加层。即使我将其旋转回纵向,它仍然可以正常工作。
// call to retrieve and parse json data
Intent i = new Intent(this,HttpExample.class);
startActivity(i);
List<Overlay> mapOverlays;
mapOverlays = mapView.getOverlays();
mapView.getOverlays().clear();
// display current location overlay
GeoPoint point = new GeoPoint((int)(lat * 1E6), (int)(lon *1E6));
controller.animateTo(point);
Drawable drawable = this.getResources().getDrawable(R.drawable.mark_red);
itemizedOverlay = new MapItemizedOverlay(drawable,this);
OverlayItem overlayItem = new OverlayItem(point, "", "");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
// Go through loaded arrays to display additional overlays
drawable = this.getResources().getDrawable(R.drawable.mark_blue);
itemizedOverlay = new MapItemizedOverlay(drawable, this);
for(int r=0; r<10; r++)
{
GeoPoint point2 = new GeoPoint((int)(lat_coordinates[r]*1E6), (int)(lng_coordinates[r]*1E6));
overlayItem = new OverlayItem(point2, "", "");
itemizedOverlay.addOverlay(overlayItem);
mapView.invalidate();
}
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
mapView.invalidate();
}
// When the activity starts up, request updates
@Override
protected void onResume() {
super.onResume();
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10,
1000*60*1, this);
}