【问题标题】:google maps api latlng not working谷歌地图 api latlng 不起作用
【发布时间】:2013-09-17 23:36:20
【问题描述】:

我正在尝试使用 jQuery 从数据标签中设置地图的纬度。由于某种原因,它永远不会起作用。如果我对值进行硬编码,它很好,但如果我尝试从数据标签中调用它,它只会失败但没有 js 错误。

感谢任何帮助

http://jsfiddle.net/4jNTs/

$(function (){

    var co = $("#map").data("co");
    var map;
    var myLatlng = new google.maps.LatLng(co);
    var mapOptions = {
        center: myLatlng,
        zoom: 4
    }; 
    map = new google.maps.Map(document.getElementById("map"), mapOptions);
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'title',
        icon: 'http://www.richardgrantham.com/img/marker.png'
    });
});

【问题讨论】:

标签: jquery google-maps


【解决方案1】:

改变 <div id="map" data-co="-41.286713, 174.773063"></div>

<div id="map" data-co="[-41.286713, 174.773063]"></div>

var myLatlng = new google.maps.LatLng(co);

var myLatlng = new google.maps.LatLng(co[0],co[1]);

latlng 构造函数需要两个数字,你给它这个字符串"-41.286713, 174.773063"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多