4

Iam building sample android app . Initially am displaying list with some cities.by clicking on any one of the city it will display map regarding to that city.

now am suffering with how to connect selected city from list with googlemap.any idea please let me know.

3 Answers 3

2

You simply make the list of city objects. Each object will contain the name of the city and the location (latitude, longitude). When you click an item, go to a map activity passing the location in the Intent object. In the map activity you'll parse the location and tell the map to go to that point.

Sign up to request clarification or add additional context in comments.

2 Comments

yeah you are right but am unable to getting latitude and logitude?
If you haven't already done so, your list adapter should extends ArrayList<City>. The object City should contain name, latitude, longitude. When an item is clicked, you get the city object from the onItemClicked of the ListView. This method gives you the item position in the array and you get City item = cities.get(position);. Then you make an intent and put in it's bundle the latitude and longitude this way: Intent intent = new Intent(MyActivity.this, MyMapActivity.class); intent.putExtra("latitude", item.getLatitude()); intent.putExtra("longitude", item.getLongitude());startActivity(intent);
0

Firstly, U have, for example database(or local data structure in your list activity) with cities and corresponding coordinates. Then, in onListItemClick() you create new intent and insert to it's extras necessary data (title, coordinates or primary key of the row in db table). Start new activity extended MapActivity with this intent, take mMapController = mMapView.getController(); and animate to mMapController.animateTo(new GeoPoint((int)yourLatitudeE6,(int)yourLongitudeE6)), where yourLatitudeE6 and yourLongitudeE6 - extras from intent

1 Comment

how will i take city name on that?
0

I think you should have lat and long of city .So you can send that lat and long to mapview through bundle and populate map of that city. In this link you can get complete tutorial for mapview . http://www.vogella.com/articles/AndroidGoogleMaps/article.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.