Javascript GoogleMaps:将额外参数传递到GeoCoder for InfoWindows
这是我的第一篇文章。我完全被卡住了,需要一些帮助才能将infoWindows添加到谷歌地图中。我实际上要使用的数据(不是我在这里使用的API)没有lat/lon,并且有多个值 在Javascript GoogleMaps:将额外参数传递到GeoCoder for InfoWindows,javascript,google-maps,google-maps-api-3,scope,Javascript,Google Maps,Google Maps Api 3,Scope,这是我的第一篇文章。我完全被卡住了,需要一些帮助才能将infoWindows添加到谷歌地图中。我实际上要使用的数据(不是我在这里使用的API)没有lat/lon,并且有多个值 在infoWindow之前一切正常,但我无法将任何其他参数传递到geocoder回调中。提前感谢您的帮助 应归功于俞明辉:。Mine在信息窗口中使用不同的数据,可能会有大约30个标记 以下是相关代码: var map=new google.maps.map(document.getElementById('map'){ 缩
infoWindow
之前一切正常,但我无法将任何其他参数传递到geocoder
回调中。提前感谢您的帮助
应归功于俞明辉:。Mine在信息窗口中使用不同的数据,可能会有大约30个标记
以下是相关代码:
var map=new google.maps.map(document.getElementById('map'){
缩放:3,
中心:新google.maps.LatLng(0,0),
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var infowindow=new google.maps.infowindow();
var标记;
var i;
var映射数据;
var位置=[];
$(文档).ready(函数(){
$.ajax({
网址:'http://api.openweathermap.org/data/2.5/weather?q=London,英国',
async:false,
成功:函数(mapData){
locations.push(mapData.name);
}
});
初始化();
});
函数初始化(){
设置标记(地图、位置);
}
函数设置标记(映射、地址){
对于(变量i=0;i
您已将myData声明为全局变量
但是这里有mapData
作为ajax成功回调的参数
$(document).ready(function () {
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather?q=London,uk',
async: false,
success: function (mapData) { //locally scoped which can't override
locations.push(mapData.name);
}
});
这不会覆盖全局变量
你应该这样做
var gmapData = {};
像这样使用它
$(document).ready(function () {
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather?q=London,uk',
async: false,
success: function (mapData) {
locations.push(mapData.name);
gmapData = mapData; //assign mapData to global variable
}
});
现在在infoWindow
google.maps.event.addListener(marker, "click", function () {
//infowindow.setContent() will accept only string
//whereas temp is numeric, so convert to string
infowindow.setContent(gmapData.main.temp.toString());
infowindow.open(map, marker);
});
google.maps.event.addListener(marker, "click", function () {
//infowindow.setContent() will accept only string
//whereas temp is numeric, so convert to string
infowindow.setContent(gmapData.main.temp.toString());
infowindow.open(map, marker);
});