Google Maps API - 未定义的ROADMAP属性?

时间:2011-09-07 17:49:02

标签: google-maps google-maps-api-3

我正在我的网站上实施两种不同类型的谷歌地图。

  1. 第一个只使用MapTypeID:

    显示带有标记的预定义位置

    mapTypeId:google.maps.MapTypeId.ROADMAP

  2. 第二个允许用户通过在地图上拖放标记等进行交互。

  3. 我正在调用我的API:

    <script src="http://maps.google.com/maps?file=api&v=2.x&sensor=false&key=ABQIAAAAfK8z5AsiUZwKZF5CkZMF6BTAb5FWVJrlydeWm3IWDEdBI1HaUhTpyn3_qR2q3IPbPnQKou9lkKVqIA" type="text/javascript"></script>
    

    启动我的第一张地图时出现此错误:

    Uncaught TypeError: Cannot read property 'ROADMAP' of undefined
    

    如果我以其他方式加载Google Maps API:

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    

    第一张地图的错误消失但我现在在启动第二张地图时遇到此错误:

    Uncaught ReferenceError: GOverlay is not defined
    Uncaught ReferenceError: GControl is not defined
    Uncaught ReferenceError: GControl is not defined
    Uncaught ReferenceError: GCopyright is not defined
    

    我认为这个问题与需要旧版谷歌地图API的地图有关。是否可以加载两个单独的谷歌地图API?

    由于

3 个答案:

答案 0 :(得分:2)

google.maps.MapTypeId.ROADMAP是谷歌地图v3的东西,但你所做的一切都是v2的事情。请尝试使用google.maps.MapType.G_NORMAL_MAP。 (然后,考虑将整个事物升级到v3。)

答案 1 :(得分:2)

如果您使用Google Maps v3

javascript包含谷歌地图api已更改:

而不是: http://maps.google.com/maps/api/js?sensor=false

必须有: https://maps.googleapis.com/maps/api/js?sensor=false

请参阅此链接 https://developers.google.com/maps/documentation/webservices/

答案 2 :(得分:0)

而不是使用它:

mapTypeId:google.maps.MapTypeId.ROADMAP

使用它:

mapTypeId:&#39;路线图&#39;