谷歌地图Javascript API V3:标记具有相同的标题
Google maps Javascript API V3 : Markers have same title
我在使用 Google Maps API V3 时遇到了困难。我能够在地图上显示多个标记(3 个标记),但每个标记都有相同的标题(Maurice GENEVOIX)。你能帮我/告诉我怎么做吗?我想不通。我有下面的代码:
function initialize() {
var myMarker=null;
var i=0;
var GeocoderOptions;
var myGeocoder;
var nom;
var temp;
var info = [
['57 Avenue Joseph Kessel 78180 Montigny-le-Bretonneux','Paul VERLAINE'],
['24 Rue du champ d avoine 78180 Mintigny-le-Bretonneux','Pauline VERLAINE'],
['21 Rue du Poirier Saint Martin 78180 Mintigny-le-Bretonneux','Maurice GENEVOIX']
];
var mapOptions = {
center: new google.maps.LatLng(48.772, 2.028),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
function GeocodingResult( results , status , i)
{
if(status == google.maps.GeocoderStatus.OK){
myMarker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: nom,
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
});
} else {
alert("L'adresse n'a pas pu etre geocodee avec succes.");
}
}
for(i=0;i<info.length;i++){
GeocoderOptions={
'address' : info[i][0],
'region':'FR'
};
nom=info[i][1];
myGeocoder = new google.maps.Geocoder();
myGeocoder.geocode( GeocoderOptions, GeocodingResult );
}
}
google.maps.event.addDomListener(window, 'load', initialize);
这是一个JavaScript闭包问题,而不是Google Maps JS API的问题。下面介绍了如何定义回调,以便获取正确的i
值。(我冒昧地采用了您的GeocodingResult
函数并内联了它。
演示
myGeocoder.geocode( GeocoderOptions, function(i){
return function(results, status){
if(status == google.maps.GeocoderStatus.OK){
markers.push( new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: info[i][1],
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
}));
} else {
alert("L'adresse n'a pas pu etre geocodee avec succes.");
}
}
}(i)); // this sends the current i into the closure of the callback.
相关文章:
- 使用Google Feeds API获取RSS Feed标题
- 删除YouTube API标题标签开头的前24个字符
- 如何在AngularJS中从RT API调用中使电影总标题不重复
- 谷歌地图Javascript API V3:标记具有相同的标题
- 如何在javascript w Ajax和JSON中使用v3 URL API获取Youtube视频标题
- JSF:Javascript google maps API - 标记获得相同的标题
- 在地图框 API 中向多点标记图层添加标题和描述
- 交叉骑士API,获取打开的选项卡标题
- 从 API 抓取页面标题是未定义的警报
- 开始..Youtube API通过Javascript提供最新的上传视频,标题和描述
- 使用Fotoraama api自定义缩略图和标题
- Reddit API/API/morechildren返回“;否'访问控制允许来源'标题“;使用moot
- 使用Tumblr API从帖子标题中提取第一句话
- 需要在照片弹出使用Facebook相册图API的标题
- Youtube Javascript API嵌入在视频结束后有2个标题栏
- 谷歌地图API:未定义标记标题
- 谷歌地图API标记标题
- Youtube Iframe Api获取视频标题
- 谷歌地图API,自定义标记问题(标题中无法解释)
- 谷歌地图API标记循环没有正确更改标题