Je souhaite utiliser mon icône de personnalisation sur la carte Google et ajouté l'URL de l'icône sur le code. Mais cela ne réfléchit toujours pas sur la carte. Quelqu'un peut-il suggérer, ce qui me manque ici. Pourquoi l’icône ne change pas, après l’ajout de l’icône " http://google-maps-icons.googlecode.com/files/sailboat-tourism.png ".
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var markers = [
{
"title": 'This is title',
"lat": '-37.801578',
"lng": '145.060508',
"icon": 'http://google-maps-icons.googlecode.com/files/sailboat-tourism.png',
"description": 'Vikash Rathee. <strong> This is test Description</strong> <br/><a href="http://www.pricingindia.in/pincode.aspx">Pin Code by
City</a>'
}
];
</script>
<script type="text/javascript">
window.onload = function () {
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 10,
flat: true,
styles: [ { "stylers": [ { "hue": "#4bd6bf" }, { "gamma": "1.58" } ] } ],
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
for (i = 0; i < markers.length; i++) {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title
});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>
<div id="dvMap" style="width: 100%; height: 100%">
</div>
nous pouvons changer l'icône des marqueurs, je l'ai fait lors d'un clic droit sur l'événement . Voyons si cela fonctionne pour vous ...
// Create a Marker
var marker = new google.maps.Marker({
position: location,
map: map,
title:'Sample Tool Tip'
});
// Set Icon on any event
google.maps.event.addListener(marker, "rightclick", function() {
marker.setIcon('blank.png'); // set image path here...
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: 'your-icon.png'
});
essaye ça
var locations = [
['San Francisco: Power Outage', 37.7749295, -122.4194155,'http://labs.google.com/ridefinder/images/mm_20_purple.png'],
['Sausalito', 37.8590937, -122.4852507,'http://labs.google.com/ridefinder/images/mm_20_red.png'],
['Sacramento', 38.5815719, -121.4943996,'http://labs.google.com/ridefinder/images/mm_20_green.png'],
['Soledad', 36.424687, -121.3263187,'http://labs.google.com/ridefinder/images/mm_20_blue.png'],
['Shingletown', 40.4923784, -121.8891586,'http://labs.google.com/ridefinder/images/mm_20_yellow.png']
];
//inside the loop
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: locations[i][3]
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(23.016427,72.571156),
map: map,
icon: 'images/map_marker_icon.png',
title: 'Hi..!'
});
appliquer le chemin local sur l'icône uniquement
Vous devez ajouter la carte ciblée:
var markers = [
{
"title": 'This is title',
"lat": '-37.801578',
"lng": '145.060508',
"map": map,
"icon": 'http://google-maps-icons.googlecode.com/files/sailboat-tourism.png',
"description": 'Vikash Rathee. <strong> This is test Description</strong> <br/><a href="http://www.pricingindia.in/pincode.aspx">Pin Code by
City</a>'
}
];
Manish, Eden après ta suggestion: voici le code. Mais toujours en affichant l'icône rouge (par défaut).
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var markers = [
{
"title": 'This is title',
"lat": '-37.801578',
"lng": '145.060508',
"icon": 'http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_green.png',
"description": 'Vikash Rathee. <br/><a href="http://www.pricingindia.in/pincode.aspx">Pin Code by City</a>'
}
];
</script>
<script type="text/javascript">
window.onload = function () {
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 10,
flat: true,
styles: [ { "stylers": [ { "hue": "#4bd6bf" }, { "gamma": "1.58" } ] } ],
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
for (i = 0; i < markers.length; i++) {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon: markers[i][3],
title: data.title
});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>
<div id="dvMap" style="width: 100%; height: 100%">
</div>