0

我被赋予了将我们的 API 调用从 v2 更新到 v3 的任务,这是它正在呈现的代码。然而返回的谷歌地图只是一个空白空间,所以很明显我做错了什么。

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

        <script type="text/javascript">
        function onLoad(xLat,yLong,strAddress,mapname) {

            var map = new google.maps.Map(document.getElementById(mapname));


        //map.addControl(new GMapTypeControl());
         alert(xLat);
            var initialLocation = new google.maps.LatLng(xLat,yLong);

        var point = new google.maps.Point(xLat,yLong);

        // Create a marker whose info window displays the given number.
        function createMarker(point, number, strMessage) {
            var marker = new google.maps.Marker(point);


        // Show this marker's index in the info window when it is clicked.
        google.maps.event.addListener(marker, 'click', function() {
            marker.openInfoWindowHtml(strMessage);
        });

        return marker;
        }

        var marker = createMarker(point, 1, strAddress);
        marker.setMap(map);

        }
        </script>
4

2 回答 2

0
  1. 在 v2 中,Point 和 LatLng 有时可以互换使用。使用 google.maps.LatLng 作为地理坐标
  2. 您需要提供选项来初始化地图的中心、缩放和类型。
  3. marker.openInfoWindow 是 v2 方法,您需要将其替换为v3 等效项。
  4. 您的 google.maps.Marker 构造函数的语法不正确,它需要一个MarkersOptions对象。

    <script type="text/javascript">
    function onLoad(xLat,yLong,strAddress,mapname) {
      var initialLocation = new google.maps.LatLng(xLat,yLong);
      var mapOptions = {center: initialLocation,
                        zoom: 8,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                       };
      var map = new google.maps.Map(document.getElementById(mapname), mapOptions);
      var marker = createMarker(map, initialLocation, 1, strAddress);
      marker.setMap(map);
    }
    function createMarker(map, point, number, strMessage) {
      var marker = new google.maps.Marker({position: point});
      var infowindow = new google.maps.InfoWindow({});
      // Show this marker's index in the info window when it is clicked.
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(strMessage);
        infowindow.open(map,marker);
      });
    
      return marker;
    }
    
    </script>
    
于 2013-11-04T16:49:31.000 回答
0

检查这个:https ://developers.google.com/maps/documentation/javascript/v2/v2tov3 :) 问候 -Vitor

于 2013-11-04T16:27:12.420 回答