Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google地图问题从数据库寻址位置_Javascript_Google Maps Api 3 - Fatal编程技术网

Javascript Google地图问题从数据库寻址位置

Javascript Google地图问题从数据库寻址位置,javascript,google-maps-api-3,Javascript,Google Maps Api 3,该行不工作,控制台中没有错误 position: new google.maps.LatLng( coordsArray[i].location ), 由警报确认的数据(coordsArray[i].位置)位置数据库字段以字符串形式返回LatLng-43.59670172.38247 这行代码有效:position:new google.maps.LatLng(-43.59670172.38247), 什么是与上面相同的数据,我的代码有什么问题吗 var list_location=loca

该行不工作,控制台中没有错误

position: new google.maps.LatLng( coordsArray[i].location ),
警报确认的数据(coordsArray[i].位置)位置数据库字段以字符串形式返回LatLng-43.59670172.38247

这行代码有效:
position:new google.maps.LatLng(-43.59670172.38247),
什么是与上面相同的数据,我的代码有什么问题吗

var list_location=localStorage.getItem('myHouse');
var obj=JSON.parse(列表位置);
var coordsArray=obj;
var标记;
var-locX;
var图像处理http://apppics.weebly.com....png';
var map=Appery(“googlemap_6”).options.mapeElement.gmap('get','map');
var CreateMarker=函数(coordsArray,i){
var marker=new google.maps.marker({
位置:新建google.maps.LatLng(coordsArray[i].位置),
//位置:new google.maps.LatLng(-43.59670172.38247),
标题:coordsArray[i]。店名,
地图:Appery(“谷歌地图6”).gmap,
});
对于(var i=0,j=coordsArray.length;iCreateMarker(coordsArray,i);
这是不正确的:
新建google.maps.LatLng(coordsArray[i].location)

您声明:“location been数据库字段以字符串形式返回LatLng-43.59670172.38247。”

构造函数将两个数字作为参数(不是逗号分隔的字符串)

如果
coordsArray[i].location
是逗号分隔的字符串,请将其转换为两个数字

var coords = coordsArray[i].location.split(",");
var latLng = new google.maps.LatLng(parseFloat(coords[0]), parseFloat(coords[1]));
var marker = new google.maps.Marker({
  position: latLng,
  map: map
});
代码片段:

var地理编码器;
var映射;
函数初始化(){
var map=new google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
变量位置=“-43.59670172.38247”;
coords=location.split(“,”);
var latLng=new google.maps.latLng(parseFloat(coords[0]),parseFloat(coords[1]);
var marker=new google.maps.marker({
位置:latLng,
地图:地图
});
地图设置中心(latLng);
}
google.maps.event.addDomListener(窗口“加载”,初始化);
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}