Jquery没有在Wordpress中加载地图

时间:2016-06-04 18:13:49

标签: javascript jquery wordpress

我正在使用jquery加载Google地图。在我多次刷新页面之前,地图不会加载正确的位置。

这是脚本:

var geocoder;
var map;

function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 13,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map"), myOptions);
}

function codeAddress(address) {
    geocoder.geocode({
        'address': address
    }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new MarkerWithLabel({
                position: results[0].geometry.location,
                map: map,
                labelContent: address,
                labelAnchor: new google.maps.Point(22, 0),
                labelClass: "labels", // the CSS class for the label
                labelStyle: {
                    opacity: 1.0
                }
            });
        } else {
            //alert("Geocode was not successful for the following reason: " + status);
        }
    });
}
initialize();

知道我在这里缺少什么吗?感谢您提出的所有建议!

0 个答案:

没有答案