Javascript google maps移动标记从ajax成功返回的lat/lng数据
正在尝试使用sql db中的lat/long坐标移动间隔上的标记/映射Javascript google maps移动标记从ajax成功返回的lat/lng数据,javascript,ajax,google-maps,google-maps-api-3,Javascript,Ajax,Google Maps,Google Maps Api 3,正在尝试使用sql db中的lat/long坐标移动间隔上的标记/映射 function initialize() { var myLatLng = new google.maps.LatLng(41,14); var myOptions = { zoom: 16, center: myLatLng, scrollwheel: false, panControl: true, zoomControl
function initialize() {
var myLatLng = new google.maps.LatLng(41,14);
var myOptions = {
zoom: 16,
center: myLatLng,
scrollwheel: false,
panControl: true,
zoomControl: true,
mapTypeControl: true,
scaleControl: true,
streetViewControl: true,
overviewMapControl: true,
mapTypeId: google.maps.MapTypeId.SATELLITE,
}
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
marker = new google.maps.Marker({
position: myLatLng,
map: map,
draggable: false
});
}
google.maps.event.addDomListener(window, 'load', initialize);
function getCoords() {
$.ajax({
url: "../ajaxscript.php",
type: "POST",
data: {
foo : "bar"
},
dataType: "text",
success: function(returnedData) {
alert(returnedData);
moveMarkerMap(returnedData);
}
});
}
function moveMarkerMap(newCoords) {
var newLatLang = new google.maps.LatLng(newCoords);
map.panTo(newLatLang);
marker.setPosition(newLatLang);
}
window.setInterval(getCoords, 5000);
在moveMarkerMap()中设置新的google.maps.LatLng(14,41)将移动它,返回的数据显示在alert()中,但与moveMarkerMap()一起使用时,标记不会移动
ajax返回的字符串格式正确;(9.624672,7.242244)如警报()所示
所以不确定为什么它不工作。google.maps.LatLng构造函数使用两个数字作为参数。这行不通:
var newLatLang = new google.maps.LatLng(newCoords);
您需要将newCoords转换为两个数字
ajax调用返回的数据是“13.444,98.7777”。。。当我手动输入时,为什么不起作用呢?那是一个字符串,不是两个数字。我同意这一点。我想这是可行的,因为所有的lat/lng坐标都是以这种格式存储的:)谢谢你指出,我会试试!如果其他人遇到此问题,请拆分字符串:success:function(returnedData){//alert(returnedData);var coordsArray=returnedData.split(“,”);moveMarkerMap(coordsArray[0],coordsArray[1]);}