首页 新闻 会员 周边 捐助

Google Map的Javascript API如何使用

0
悬赏园豆:20 [已解决问题] 解决于 2015-06-03 14:19
<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
      html, body, #map-canvas { height: 100%; margin: 0; padding: 0;}
    </style>
    <script type="text/javascript"
      src="http://www.google.cn/maps/api/js">
    </script>
    <script type="text/javascript">
    var geocoder;
    var map;
    var infowindow = new google.maps.InfoWindow();
    var marker;

    function initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(40.730885,-73.997383);
      var mapOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: 'roadmap'
      }
      map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
      //codeAddress();
    }

    function codeAddress() {
      //var address = document.getElementById("address").value;
      var address = "上海市南京西路1618號6樓";
      geocoder.geocode( { 'address': address}, function(results, status) {
        console.log(status);
        console.log(results);
        console.log(google.maps.GeocoderStatus);
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.location);
          var marker = new google.maps.Marker({
              map: map,
              position: results[0].geometry.location
          });
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }




      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <button onclick="codeAddress()">Click</button>
<div id="map-canvas"></div>
  </body>
</html>

调用Google "MAP"接口是一定使用www.google.cn,因为http://www.google.cn/maps/中,我无法找到是如何调用API的方法和参数.在codeAddress()方法,总是返回"ZERO_RESULTS"

五毛钱的饼的主页 五毛钱的饼 | 小虾三级 | 园豆:517
提问于:2015-06-02 10:41
< >
分享
最佳答案
0

解决了

五毛钱的饼 | 小虾三级 |园豆:517 | 2015-06-03 14:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册