我通过查找用户位置创建了一个地图标记,该标记位于我的地图上,但我正在尝试向地图标记添加字符串,但无法使其正常工作。这是我设置位置的 onCreate 方法。该方法的最后一部分显示将精确定位在位置,我认为覆盖项将采用字符串参数,如下所示:
@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();
}
}
谁能看到我做错了什么?这是错误的方法吗?最终,我想将名称和高分传递给将从另一个类中检索为两个字符串的位置。
我很感激任何建议。