Draw circles around multiple markers in Maps

Newtt

I need to place circles around multiple markers in Maps API v3

This is what I've done so far:

function initialize(){
    var locations = [
      ['Band Stand', 19.04519, 72.819091],
      ['Gateway Of India Mumbai', 18.921984, 72.834654],
      ['Haji Ali', 18.9778192, 72.8104819],
      ['Kings Circle', 19.032261, 72.857225],
    ];
    var map = new google.maps.Map(document.getElementById('map-sec'), {
      zoom: 12,
      center: new google.maps.LatLng(19.0822507,72.8811862),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();
    var marker, i;
    var circle = new google.maps.Circle({
      map: map,
      radius: 1000,
      fillColor: '#AA0000'
    });
    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });
      circle.bindTo('center', marker, 'position');
      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
        })(marker, i));
    }
}
google.maps.event.addDomListener(window, 'load', initialize);

However, this is giving me a circle around only one of the locations. What should I do to get multiple circles?

Jonas Grumann

Try moving this:

var circle = new google.maps.Circle({
  map: map,
  radius: 1000,
  fillColor: '#AA0000'
});

..inside the for loop:

for (i = 0; i < locations.length; i++) {
      var circle = new google.maps.Circle({
      map: map,
      radius: 1000,
      fillColor: '#AA0000'
    });
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map
  });
  circle.bindTo('center', marker, 'position');
  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);
    }
    })(marker, i));
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Placing Circles instead of Markers in google maps

分類Dev

Removing multiple circles google maps api

分類Dev

android maps api v2 adding multiple circles

分類Dev

How to Add Google Maps with Multiple Markers Showing Infowindows on Load and on Click

分類Dev

Fade In circles in Google Maps

分類Dev

How to draw circles on the perimeter of a circle?

分類Dev

Draw circle around an imageview

分類Dev

Adding multiple circles to MapKit

分類Dev

Adding Multiple Markers in real time google maps v2 android

分類Dev

ReactJS and Google Maps - Displaying Markers

分類Dev

Draw CALayer border around UIView

分類Dev

amCharts Maps not loading circles on page refresh

分類Dev

Markers with multiple colours and Geocoder

分類Dev

Google maps delete all markers and then create new

分類Dev

How to apply CSS to Here Maps API Markers

分類Dev

Google Maps: infobox turns up behind markers?

分類Dev

Google Maps fit markers in custom bounds

分類Dev

Google maps API markers content hide by default

分類Dev

How to draw line on google maps

分類Dev

AngularJS Google Map with Multiple Markers

分類Dev

Add infoWindows to multiple markers in array

分類Dev

OpenCV draw rectangles around only large contours?

分類Dev

GoogleMaps API (Android) – Draw PolyLine between the edges of Markers adjusting with Zoom

分類Dev

WebGL draw multiple objects

分類Dev

Cannot draw multiple lines

分類Dev

Draw on Canvas multiple times

分類Dev

How to hide/show groups of markers by category with Google Maps in Android?

分類Dev

Google Maps API 3 - Show All Markers on Screen, but Keep Centerpoint

分類Dev

How to get all markers in google-maps-react

Related 関連記事

ホットタグ

アーカイブ