我创建了一个地图标记,通过查找用户位置在我的地图上定位,但我试图向地图标记添加字符串,但无法使其工作。这是我设置位置的onCreate方法。的方法将显示在精确位置的最后一部分,我认为覆盖项目将采取字符串参数如下:如何将字符串添加到Android中的自定义地图标记中?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
// Displaying Zooming controls
mapView= (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
//Manually place a pin by touching the map
touchy t = new touchy();
overlayList = mapView.getOverlays();
overlayList.add(t);
compass = new MyLocationOverlay(Maps.this, mapView);
overlayList.add(compass);
controller = mapView.getController();
d = getResources().getDrawable(R.drawable.androidmarker);
//placing pinpoint at location
lm =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria crit = new Criteria();
towers = lm.getBestProvider(crit, false);
Location location = lm.getLastKnownLocation(towers);
if(location != null){
lat = (int) (location.getLatitude()* 1E6);
longi = (int) (location.getLongitude()* 1E6);
GeoPoint ourLocation = new GeoPoint(lat, longi);
controller.animateTo(ourLocation);
controller.setZoom(6);
OverlayItem overlayitem = new OverlayItem(ourLocation, "First string", "Second string");
HelloItemizedOverlay custom = new HelloItemizedOverlay(d, Maps.this);
custom.insertPinpoint(overlayitem);
overlayList.add(custom);
}
else{
Toast.makeText(Maps.this, "Couldn't get provider", Toast.LENGTH_SHORT).show();
}
}
有人能看到我在做什么错?这是做错了吗?最终,我想传递一个名称和高分到将从另一个班级作为两个字符串检索的位置。
我很欣赏任何建议。
无论是标题还是片段是通过'ItemizedOverlay'显示给你。 – CommonsWare 2012-04-06 15:19:56