【发布时间】:2014-03-03 22:52:03
【问题描述】:
我正在尝试传递一个将数组带入谷歌地图 api v3 的函数。 这是我的代码:
function buscarCoords(callback){
var result = result;
connection.query('SELECT * FROM monitoreo_actual', function(err, result){
if(err){
console.log(err);
}
callback({result:result});
});
}
function initialize() {
//var location = new google.maps.LatLng(10.191, -68.191);
var mapOptions = {
center: new google.maps.LatLng(10.191, -68.191),
zoom: 8,
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
marker = new google.maps.Marker({
position: buscarCoords(function(resultsObject){
new google.maps.LatLng(ConvertFromGrdToGoogle(resultsObject.result).LtLn);
}),
map: map
});
}
在这段代码中,ConvertFromGrdToGoogle 是一个函数,正如它所说,它将数据转换为谷歌可以接受的格式。它可以像这样工作并返回坐标:
[ '10.1850, -68.334',
'10.1850, 68.334',
'10.1853, -68.334',
'10.1853, -68.334' ]
现在的问题是,即使加载了地图,它也不会显示标记。
【问题讨论】:
-
A google.maps.LatLng 将两个数字作为其参数。不是带有逗号的字符串(或此类字符串的数组)。
标签: javascript arrays node.js google-maps-api-3 google-maps-markers