Google Maps API加载问题 [英] Google Maps API Loading Issue

查看:125
本文介绍了Google Maps API加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过AJAX调用异步加载Google Maps API,并且没有发现错误的儿子屏幕,并且Google API代码正确输出,并且我有有效的纬度/经度坐标。我正在使用下面的代码,任何人都可以提出有关正在发生的事情的任何想法?

I'm asynchronously loading the Google Maps API via an AJAX call and I'm getting no error son screen and the Google API code is outputting correctly and I have valid lat/lng coords., I'm using the below code, can anyone suggest any ideas as to what is going on?

<script type="text/javascript">
function initialize() {
    var mapOptions = {
        center: new google.maps.LatLng({lat}, {lng}),
        zoom: 16,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}           
function loadScript()
{
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.googleapis.com/maps/api/js?key={api_key}&sensor=false&callback=initialize";
    document.body.appendChild(script);
}
window.onload = loadScript;
</script>
<div id="map-canvas" class="map-canvas"></div>


推荐答案

解决这个问题,在Google API文档中进行异步加载我使用的代码在地图上的地图 https://developers.google.com/maps/documentation/javascript/tutorial#asynch ,问题是我是使用:

Solved it, on the Google API documentation for asynchronously loading the map I used the code as it is on the page https://developers.google.com/maps/documentation/javascript/tutorial#asynch, the issue was I was using:

window.onload = loadScript;

当我应该使用时:

When I should have been using:

window.onload = loadScript();

这篇关于Google Maps API加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆