Guido Tarsia
Guido Tarsia

Reputation: 2172

How to only show certain area in Google Maps?

I'm aware that this question was asked here (e.g. Google map v2 api: how to show a specific map area,
MKCoordinateRegionMakeWithDistance equivalent in Android,
get bounds of a location in google map android v2, etc.)

But I don't feel any of them really solve the problem.

I want to hide everything OUTSIDE the black rectangle, maybe make the outside area thansparent, or not show it at all, which is different than downloading it, rendering it and then hide it by overlaying some polygons.

Example

I thought of creating rectangles that take every other part of the map, but I'm not sure if there's gonna be a big performance drop. I don't know how well GMaps handle polygons.

So far I handle the onCameraChange, and move the camera whenever map goes out of specified area. This works ok, but I want to hide everything else.

Upvotes: 1

Views: 3353

Answers (2)

Qadir Hussain
Qadir Hussain

Reputation: 8856

If you want to just the static map image of any area with a marker. then why not use the google static maps API.

like this

public String getElectedOfficialMapUrl(String lat, String lng) {
    String url = null;

    url = "http://maps.google.com/maps/api/staticmap?center=" + lat + ","
            + lng
            + "&zoom=15&maptype=roadmap&size=250x300&markers=color:red|"
            + lat + "," + lng + "&sensor=false";

    return url;
}

this will return a static map image in JPG with a marker centered.

i.e http://maps.google.com/maps/api/staticmap?center=29.54547854,-95.45514544&zoom=15&maptype=roadmap&size=250x300&markers=color:red|29.54547854,-95.45514544&sensor=false

hope this helps

Upvotes: 0

Lmoro
Lmoro

Reputation: 71

I think this is not a good thing to do, but if you don't like to constrain the camera over a certain area (wich is not good) you can use polygons, I don't know if it will be an easy job.

I suggest you to do not hide anything, if the user want to see your marker on the map he can see it at any zoom level, so if he want to procrastinate around that's won't be a problem, he can always come back with a zoom out to locate your marker and a zoom in to reach the area.

Upvotes: 0

Related Questions