开发者

Click on a map point to launch new activity with additional point information

I have a map with a couple of markers on it. These markers are pulled from a List that includes the names, latitude, longitude, and a descriptions of the places. What I would like to happen is when I click on a marker, a new activity would launch that would show the details of the point clicked. I have built out the xml for the view, just I don't know how to get the details of the point from the list in my "MapActivity" that I clicked on into the new activity which is going to show all that points details. Kind of like when you click on a point in Google maps on Android, then click on that point's ballo开发者_如何学Goon popup to get more information about that point.

I can find tutorials on how to make a toast appear with the points "name, lat and long" (which are part of the GeoPoint, but that is it. Nothing on making a whole new screen popup with info on that point clicked.

Any help would be greatly appreciated!


Create a class that extends ItemizedOverlay (which a already assume you've done). Then override the OnTap method like so:

@Override
protected boolean onTap(int index) {
         //Use the index to get the item
         MyOverlayItem item = mOverlays.get(index); /*something like this */
         //Use the item to get the coordinates
         double lat = item.lat; /*You would have to write these in the MyOverlayItem class */
         double lng = item.lng;
         //Create a new intent and start it
         Intent i = new Intent(mContext, NewActivity.class);
         i.putExtra("Lat", lat);
         i.putExtra("Lng", lng);
         startActivity(i);
    }


Call up a function to fire an intent to the new activity, almost similar to the way you created a Toast

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜