Take the 2-minute tour ×

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;


        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
        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");


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);

public void onCreate(Bundle savedInstanceState) {


    mapView = (MapView) findViewById(R.id.mapview);       

    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");


    MapController mapController = mapView.getController();

    GeoPoint yourGeoPoint = new GeoPoint(latitude1,longitude1);


protected boolean isRouteDisplayed() {
    return true;


share|improve this question

1 Answer 1

up vote 0 down vote accepted

Are you using animateTo(GeoPoint geoPoint) method to go to your geo point?


You have to do something like this in your MapActivity, you can put the code in onCreate():

GeoPoint yourGeoPoint = new GeoPoint(yourLatitude*1E6, yourLongitude*1E6);

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() ).


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..


Ok so you should do this to pass your geopoints to the next activity: In your button click listener you should write this:

/* create a intent to start the new activity */
Intent intent = new Intent(this, YourMapActivity.class);
/* create a bundle to pass data to your next activity */
Bundle bundle = new Bundle();
/* put the latitude and longitude values into the bundle */
bundle.putInt("latitude_key", yourLatitudeValue); 
bundle.putInt("longitude_key", yourLongitudeValue);
/* include the bundle into your intent */
/* start your MapActivity */

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:

/* get the bundle from the button activity */
Bundle bundle = getIntent().getExtras();
/* get the latitude and longitude based on the same key you put in the ButtonActivity to send the data */
int latitude = bundle.getInt("latitude_key", 0);
int longitude = bundle.getInt("longitude_key", 0);
/* put the data into a GeoPoint and make the animation */
GeoPoint yourGeoPoint = new GeoPoint(latitude * 1E6, longitude * 1E6);

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.

share|improve this answer
Hello Cata, thank you for your reply. I am a newbie at android but looking at my files, I haven't used that. Where would I place that? –  user1117744 Jan 7 '12 at 0:43
Shall I post my Map.java file? –  user1117744 Jan 7 '12 at 0:57
Sorry for the bump but this is very important. I just tried adding this to my Map class: mapController.animateTo(locationPlace1); locationPlace1 is a overlay which I've made, and when going to the Map class, either directly or from those buttons included in the code above, it successfully goes to that overlay but I want it so that which ever overlay / location was requested by the button, the map is diverted to that location –  user1117744 Jan 7 '12 at 13:34
I'm not sure if I understand what you want but if you want that your ActivityMap to go to your overlay position, you just have to pass the overlay location to the animateTo() method and it wil do what you want. –  Cata Jan 7 '12 at 15:44
So basically, I have 3 tabs. The first tab contains buttons (the code for the first tab is in the original question). In that tab, there are buttons which when pressed, should go my Map Activity (which is does) and go to the exact location given by the longitude and latitude numbers (it doesn't do that). Since you suggested using animateTo(GeoPoint geoPoint), I'm not sure where and how I should implement that. Like what code shall I put in? –  user1117744 Jan 7 '12 at 17:40

Your Answer


