Hardi Shah
Hardi Shah

Reputation: 133

Show google map only for particular city in android

I want to show map for particular city,when user selects any city only area of that city will be displayed not whole map.I need some suggestions for doing this kind of stuff. Thanks in advance.

Upvotes: 3

Views: 3762

Answers (4)

Prachi
Prachi

Reputation: 2559

for that first you have to ask user to select a city then use Geocoder class to find lat and lng of a city use following code

    MapController mControl;
    MapView mapView;
     mapView= (MapView) findViewById(R.id.navView)
     mControl = mapView.getController();
     mControl.animateTo(GeoP); //GeoP is the geopoint of your city

Upvotes: 0

UnknownJoe
UnknownJoe

Reputation: 599

There is a good class for that purpose called Geocoder

Here is the reference

You can just use method

getFromLocationName("My Particular city", ...) 

and obtain list of locations that match it. First one is usually the one you need.

I guess, this is the only way. Very useful though. :)

Hope, it helped!)

Upvotes: 0

Mr. Sajid Shaikh
Mr. Sajid Shaikh

Reputation: 7251

Here, We need to do RND for each city, what is the latitude & longitude for each city. so for to find latitude & long. for each city no need to go there and check what is the lat. long., The simple way to do is Find coordinates by moving around the map. So After getting all lat. long. for each city. Use this lat. & long. to display map according to the user selection of city. So it will display particular area. So check following code how to use latitude & longitude to display map.

Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("geo:0,0?q=" + ("40.7890011, -124.1719112")));
            try {
                startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
            }

Hope this will help you. Thanks

Upvotes: 0

Bhavin
Bhavin

Reputation: 6010

You can Open Map via intent.

String uri = "geo:"+ latitude + "," + longitude;
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));

// You can also choose to place a point like so:
String uri = "geo:"+ latitude + "," + longitude + "?q=my+street+address";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));

/*
* The Possible Query params options are the following:
*
* Show map at location: geo:latitude,longitude
* Show zoomed map at location: geo:latitude,longitude?z=zoom
* Show map at locaiton with point: geo:0,0?q=my+street+address
* Show map of businesses in area: geo:0,0?q=business+near+city
*/

Upvotes: 1

Related Questions