Google地图错误:a为空 [英] Google map error: a is null

查看:83
本文介绍了Google地图错误:a为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我想使用谷歌地图。问题是我得到一个错误,说a是null,其中a是谷歌地图API中使用的一个变量。以下是我称之为谷歌地图的方式:

  //为Google地图创建新的中心位置
var latlng = new google.maps.LatLng(centerLatitude,centerLongitude);

//谷歌地图的选项
var myOptions = {
zoom:7,
maxZoom:12,
center:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
};

//创建新地图
var map = new google.maps.Map(document.getElementById(map_canvas),myOptions);

以下是我的HTML标签的样子:

 < div id =map_canvas>< / div> 

我通过url获取页面加载的lat和lng。这些值正确传递,所以我知道这不是问题。我认为它必须处理 var map = new google.maps.Map(document.getElementById(map_canvas),myOptions); 不正确。任何建议?



编辑:这里是错误信息:


a是
fromLatLngToPoint(a = null)
yg(a = null,b = Object {zoom = 7,maxZoom = 12,more ...})
d(d = Document Default.aspx (a){a(a = undefined)
d()
[Break On This Error]函数Qf(a){a = af [9]; return a!= i?a:...);函数sg(a){a [ic]& a [ic] Vb}


解决方案

确保您指定保存地图的元素的大小。例如:

 < div id =map_canvasstyle =width:500px; height:500px;><<< ; / DIV> 

还要确保您的地图变量是在全局范围内定义的,并且
初始化映射一旦DOM被加载。


I have a program that I want to use google maps for. The problem is I get an error that says a is null where a is a var used in the google map api. Here is how I call my google map:

//Creates a new center location for the google map
    var latlng = new google.maps.LatLng(centerLatitude, centerLongitude);

    //The options for the google map
    var myOptions = {
        zoom: 7,
        maxZoom: 12,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    //Creates the new map
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

And here is what my HTML tag looks like:

<div id = "map_canvas"></div>

I get the lat and lng on page load through the url. These values are passed in correctly so I know that is not the problem. I think that it has to do with the var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); not being correct. Any suggestions?

EDIT: Here is the error message:

a is null fromLatLngToPoint(a=null) yg(a=null, b=Object { zoom=7, maxZoom=12, more...}) d(d=Document Default.aspx?lat=30.346317&lng=105.46313, f=[function()]) d(a=undefined) d() [Break On This Error] function Qf(a){a=a.f[9];return a!=i?a:...);function sg(a){a[ic]&&a[ic]Vb}

解决方案

Make sure you specify the size of the element that holds the map. For example:

<div id="map_canvas" style="width: 500px; height: 500px;"></div>

Also make sure your map variable is defined in the global scope and that you initialize the map once the DOM is loaded.

这篇关于Google地图错误:a为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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