获取并显示用户位置的网站asp.net

时间:2016-11-22 07:57:25

标签: asp.net google-maps

我正在开发一个网站,需要获取并显示用户的位置。     但是,每次运行项目时都会收到此错误消息: enter image description here

这是我的代码:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (p) {
        var LatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
        var mapOptions = {
            center: LatLng,
            zoom: 13,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
        var marker = new google.maps.Marker({
            position: LatLng,
            map: map,
            title: "<div style = 'height:60px;width:200px'><b>Your location:</b><br />Latitude: " + p.coords.latitude + "<br />Longitude: " + p.coords.longitude
        });
        google.maps.event.addListener(marker, "click", function (e) {
            var infoWindow = new google.maps.InfoWindow();
            infoWindow.setContent(marker.title);
            infoWindow.open(map, marker);
        });
    });
} else {
    alert('Geo Location feature is not supported in this browser.');
}
</script>
<div id="dvMap" style="width: 500px; height: 500px">
</div>
  </div>
    </form>
</body>
</html>

我做错了什么??? 任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

我解决了我的问题! 我刚刚添加了这行代码来添加我的API密钥:

<script src="//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key=MY_KEY" async="" defer="defer" type="text/javascript"></script>