Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá! Gostaria de implementar no array var myLatlng icones individuais e fixos para cada um deles, ao inves de utilizar a função abaixo que coloca o mesmo icone para todos. Sou leigo em js, acredito que alguem possa me ajudar. O codigo abaixo é basicamente o mesmo que no site de desenvolvedor do google maps, segue o link original: https://developers.google.com/maps/documentation/javascript/examples/icon-complex
// The following example creates complex markers to indicate beaches near
// Sydney, NSW, Australia. Note that the anchor is set to
// (0,32) to correspond to the base of the flagpole.
function initialize() {
var mapOptions = {
zoom: 12,
center: new google.maps.LatLng($lat,$lng)
}
var map = new google.maps.Map(document.getElementById('single-gmap'),
mapOptions);
setMarkers(map, myLatlng);
}
/**
* Data for the markers consisting of a name, a LatLng and a zIndex for
* the order in which these markers should display on top of each
* other.
*/
var myLatlng = [
['1', $lat,$lng, 4],
['2', 28.338166, -81.64695389999997],
['3', 28.31497, -81.597636],
['4', 28.34903251, -81.61249638],
['5', 28.31390193, -81.62090778],
['6', 28.30324714, -81.61095142],
['7', 28.31307075, -81.5823698],
['8', 28.3302221, -81.63386822],
['9', 28.34857928, -81.62142277]
];
function setMarkers(map, locations) {
// Add markers to the map
// Marker sizes are expressed as a Size of X,Y
// where the origin of the image (0,0) is located
// in the top left of the image.
// Origins, anchor positions and coordinates of the marker
// increase in the X direction to the right and in
// the Y direction down.
var image = {
url: 'images/default-marker.png',
// This marker is 20 pixels wide by 32 pixels tall.
size: new google.maps.Size(51, 70),
// The origin for this image is 0,0.
origin: new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
anchor: new google.maps.Point(0, 32)
};
// Shapes define the clickable region of the icon.
// The type defines an HTML <area> element 'poly' which
// traces out a polygon as a series of X,Y points. The final
// coordinate closes the poly by connecting to the first
// coordinate.
var shape = {
coords: [1, 1, 1, 20, 18, 20, 18 , 1],
type: 'poly'
};
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
shape: shape,
title: beach[0],
zIndex: beach[3]
});
}
}Carregando comentários...