【问题标题】:TypeError: google.maps.latLng is not a constructor [closed]TypeError:google.maps.latLng 不是构造函数[关闭]
【发布时间】:2014-03-18 19:17:34
【问题描述】:

我正在使用 Firefox 为 GeoLocation 加载我的 html 文件。问题是我在控制台中收到这两条消息:

TypeError: google.maps.latLng is not a constructor index.html:26
error in parsing value for 'background'.  Declaration dropped.

这是我的代码:

<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Navigator</title>
</head>
<script src="js/jquery.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>

<script>

x = navigator.geolocation;

x.getCurrentPosition(success, failure);

function success(position) {

    // fetch coordinates

    var mylat = position.coords.latitude;
    var mylong = position.coords.longitude;

    // google api ready latitude and longitude string

    var coords = new google.maps.latLng(mylat, mylong);

    // setting up out google map

    var mapOptions = {
        zoom: 16,
        center: coords,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }

// CREATING MAP

var map =  new google.maps.Map(document.getElementById("map"), mapOptions);
}

function failure() {
    $('#lat').html("<h3> No co-ordinates available!</h3>");
}
</script>

<body>
<!--map placeholder -->
<div id="map">

</div>

<div id="lat"></div>
<div id="long"></div>
</body>
</html>

我什至不确定来自 Google Map API 的数据是否正确加载。 有人可以帮我解决这个问题吗?

【问题讨论】:

  • 再次打错:LatLng() 而不是 latLng()。
  • 伙计们,你们都有足够高的代表知道 Anto 应该发布答案并且 Cyzanfar 应该接受它,以帮助将来阅读此问题的其他人。

标签: javascript google-maps geolocation


【解决方案1】:

TypeError:google.maps.latLng 不是构造函数

 google.maps.LatLng

使用代替

google.maps.Latlng.

就是这样,在 Google 地图中完美运行。

【讨论】:

    猜你喜欢
    • 2016-12-30
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多