0

我已经创建了MVC3 Web应用程序,我想GMAP我的联系页面上谷歌地图不工作MVC的Web应用程序

ERROR: 
Google has disabled use of the Maps API for this application. The provided key is not a valid Google API Key, or it is not authorized for the Google Maps Javascript API v2 on this site. If you are the owner of this application, you can learn about obtaining a valid key here: http://code.google.com/apis/maps/documentation/javascript/v2/introduction.html#Obtaining_Key 

代码:

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

    <script type="text/javascript"> 
     var allMarks = []; 
     google.load("maps", "2"); 

     //This function will help us to add the mark at 
     //location where user has double clicked. Then 
     //we will add all the marks in our array so that 
     //we can send it back to the controller 
     function initialize() { 
      var map = new google.maps.Map2(document.getElementById("map")); 
      map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13); 
      map.setUIToDefault(); 
      GEvent.addListener(map, "dblclick", function(overlay, latlng) { 
       if (latlng) { 
        var mark = new GMarker(latlng); 
        allMarks.push(latlng); 
        map.addOverlay(mark); 
       } 
      }); 

     } 
</script> 

布提没有看到地图上还我未能生成API密钥:

http://code.google.com/apis/maps/documentation/javascript/tutorial.html 

我想测试它在我的本地机器plz帮助。

回答

3

你为什么要使用API​​密钥注册本地测试的API?

它不再需要,除非你需要使用报告,或者你想购买additional quota如果您的网站每天产生超过25个000次地图加载。

要使用Google Libraries API,你只需要在您的网页的标题下面的脚本:

<script type="text/javascript" src="https://www.google.com/jsapi"></script> 

此外,谷歌地图的JavaScript API第2版已正式弃用,因此,你应该使用Maps Javascript API的新的version 3

var allMarks = []; 
google.load('maps','3', {other_params: "sensor=false"}); 

function initialize() { 
    var options = { 
     center: new google.maps.LatLng(37.4419, -122.1419), 
     zoom: 13, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    var map = new google.maps.Map(document.getElementById("map"), options); 
    google.maps.event.addListener(map, "dblclick", function(e) { 
     if (e.latLng) { 
      var marker = new google.maps.Marker({ 
       position: e.latLng, 
       map: map 
      }); 
      allMarks.push(e.latLng); 
     } 
    }); 
}