I have set up a MapView Class which has Overlays (and they’re working fine.)
My application is built around tabs and on my first tab, this is my code:
public void onCreate(Bundle savedInstanceState) {
Button ButtonName1;
Button ButtonName2;
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
{
ButtonName1 = (Button) findViewById(R.id.ButtonName1);
ButtonName1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:51.594748,-0.107879"));
i.setClassName("my.android.project", "my.android.project.Map"); // .Map is my MapView file
startActivity(i);
}
});
}
{
ButtonName2 = (Button) findViewById(R.id.ButtonName2);
ButtonName2_Cinema.setOnClickListener(new OnClickListener() {
public void onClick(View arg1) {
Intent ii = new Intent(Intent.ACTION_VIEW, Uri.parse("51.55748,0.07388"));
ii.setClassName("my.android.project", "my.android.project.Map");
startActivity(ii);
}
});
}
}
}
Now by clicking on those buttons, it successfully leads me onto the Map class and my overlays are displayed perfectly well, in the correct position, but it doesn’t point me to that those exact latitude and longitude positions, therefore, not directly onto the overlays.
Does anyone know why?
Here’s my MapClass:
public class Map extends MapActivity {
private MapView mapView;
public static int latitude1 = (int) (51.508170 * 1E6);
public static int longitude1 = (int) (-0.128017 * 1E6);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
OverlayMap itemizedOverlay = new OverlayMap(drawable, this);
GeoPoint location1 = new GeoPoint(latitude1, longitude1);
OverlayItem overlayitem = new OverlayItem(location1, "Title", "Contents");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
MapController mapController = mapView.getController();
GeoPoint yourGeoPoint = new GeoPoint(latitude1,longitude1);
mapController.animateTo(yourGeoPoint);
mapController.setZoom(10);
}
@Override
protected boolean isRouteDisplayed() {
return true;
}
}
Are you using
animateTo(GeoPoint geoPoint)method to go to your geo point?EDIT:
You have to do something like this in your MapActivity, you can put the code in onCreate():
I don’t know exactly how is your MapActivity to help you better but the thing is that you have to put the code above in the MapActivity where you have access to your map controler and the new coordinates (I think in onCreate() ).
EDIT II :
I think you are not sending correctly the longitude and latitude through your intent.
You have to make use of a Bundle to do that. Please read this article for more details..
EDIT III :
Ok so you should do this to pass your geopoints to the next activity:
In your button click listener you should write this:
Ok so now we have to get the data from the bundle and use it on your map.. The following code is for your MapActivity in onCreate() method:
The ButtonActivity is the activity on which you have the buttons :). Note that you have to use the same key strings in your bundle to get the correct data, just like in the example above.
I hope now everything is clear :D.