谷歌地图移动标记与纬度

谷歌地图移动标记与纬度

本文介绍了谷歌地图移动标记与纬度/液化天然气从阿贾克斯成功返回的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图将标志/图上区间的纬度/长COORDS从SQL数据库。

Trying to move marker/map on interval with lat/long coords from sql db.

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);

设置新的google.maps.LatLng(14,41)的moveMarkerMap()会移动,而returnedData在警报显示(),但moveMarkerMap使用时标记将不会移动()

Setting the new google.maps.LatLng(14,41) in moveMarkerMap() will move it, and the returnedData shows in alert() but marker won't move when used with moveMarkerMap()

从阿贾克斯返回的字符串是正确的格式; (9.624672,7.242244),如图警报()所以不知道为什么它不工作。

The returned string from ajax is correct format; (9.624672,7.242244) as shown in alert()so not sure why its not working.

推荐答案

在google.maps.LatLng构造函数有两个号码的参数。这是行不通的:

The google.maps.LatLng constructor takes two numbers for arguments. This won't work:

var newLatLang = new google.maps.LatLng(newCoords);

您需要newCoords转换成两个数。

You need to convert newCoords into two numbers.

字符串转换为经纬度谷歌地图

转换[52.43242,4.43242]谷歌经纬度

How我得到谷歌地图针从变量使用位置?

这篇关于谷歌地图移动标记与纬度/液化天然气从阿贾克斯成功返回的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 12:56