Reputation: 14142
Is it possible to hide markers that are not from a particular country? Eg I have a dropdown menu with England, Wales, Scotland etc.
If the user selects Wales - the map zooms to Wales and shows all the marker within a certain radius, but I would want to have any markers that are near the Welsh border to not appear as they are not within Wales.
Any ideas?
Upvotes: 2
Views: 1330
Reputation: 31912
Figure out the polygon that encompasses only Wales (you'll have to do that yourself; I don't think Google will magically give you that). Only draw markers that fall within that polygon.
The hard part is figuring out if a latlng coordinate is within a polygon. Here's a solution someone's worked out, but it's using the Google Maps API v2 syntax, not v3 syntax that I guess you'll be using. Fortunately someone else has already rewritten it for API 3 as well.
To create the polygon, just do something like the following. I'm guessing you don't actually want to show this, just your markers, so have made it invisible by setting both stroke and fill opacities to zero.
polygon = new google.maps.Polygon({
paths: [
new google.maps.LatLng(51.478316,-0.002888),
new google.maps.LatLng(51.479245,-0.001051),
/// ... array of all the coordinates making up the path of your polygon
],
strokeOpacity: 0.0,
fillOpacity: 0.0,
map: map
});
Upvotes: 1