I have created a map marker that is positioned on my map by finding the users location, but I am trying to add strings to the map marker and cannot get it to work. Here is my onCreate method where the location is set. The last part of the method shows placing pinpoint at location, I thought that the overlay item would take string parameters as follows:
@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();
}
}
Can anyone see what I am doing wrong? Is this the wrong way to do this? Eventually I want to pass a name and high-score to the location which will be retrieved from another class as two strings.
I appreciate any advice at all.
Follow the following tutorial:
http://codemagician.wordpress.com/2010/05/06/android-google-mapview-tutorial-done-right/
In this he is creating an ItemizedOverly
This will help you in adding a map overlay with text