0

How to highlight a particular area in Google Maps? If you go to maps.google.com and search for your location, a dotted line will highlight the area. How to do the same in Google maps API?

Julien
  • 2,139
  • 1
  • 19
  • 32
user123
  • 31
  • 1
  • 10

1 Answers1

3

You want to draw a line around an area on a map? Use the Polyline class

Update: if you want a nicely styled semi-transparent overlay like the neighbourhood examples on http://zumper.com you should use the Polygon class

Here's a sample of their JS which should give you an idea how they're doing it.

makeHood: function (hood, hoodId) {
            var hoodPoly = HOOD_CACHE[hoodId];
            if (hoodPoly) {
                hoodPoly.setOptions(hoodPolyStandardOptions)
            } else {
                var coordinates = [];
                var markerBounds = hood["bounds"][0]["exterior"];
                for (var i = 0, len = markerBounds.length; i < len; ++i) {
                    coordinates.push(new google.maps.LatLng(markerBounds[i][3], markerBounds[i][0]))
                }
                var options = angular.copy(hoodPolyInitialOptions);
                options.paths = coordinates;
                hoodPoly = new google.maps.Polygon(options);
                hoodPoly.name = hood["name"];
                hoodPoly.id = hoodId;
                hoodPoly.point = new google.maps.LatLng(hood["lat"], hood["lng"]);
                hoodPoly.mouseoverOptions = hoodPolyMouseoverOptions;
                hoodPoly.standardOptions = hoodPolyStandardOptions;
                var box = hood["box"];
                hoodPoly.box = new google.maps.LatLngBounds(new google.maps.LatLng(box[1], box[0]), new google.maps.LatLng(box[3], box[2]));
                hoodPoly.getPosition = angular.bind(hoodPoly, function () {
                    return this.point
                });
                HOOD_CACHE[hoodId] = hoodPoly
            }
            hoodPoly.hood = hood;
            return hoodPoly
        },
duncan
  • 31,401
  • 13
  • 78
  • 99
  • No,not like that view zumper.com ! I want to do like that – user123 Jan 09 '14 at 14:22
  • well if you [view their javascript](https://d2n1sxp1qtdjke.cloudfront.net/ee/js/map-compiled.js) (run it through a [JS beautifier](http://jsbeautifier.org/)) you'll see they use Polygons – duncan Jan 09 '14 at 14:48