【问题标题】:Why do I get "map.set_center is not a function"?为什么我得到“map.set_center 不是函数”?
【发布时间】:2010-12-26 18:59:15
【问题描述】:

在我昨晚更新之前,这段代码一直有效。
该代码在我的本地主机上运行良好,但在我的测试服务器上出现错误。错误消息(来自 Firebug)是 "map.set_center is not a function"

那么为什么这不再在我的服务器上工作了?

  function googleMapInit() 
  {    
    if (jQuery('#map_canvas').length > 0) {
      var currentLocation    = jQuery('#geomap_ddlCity :selected').text() + ', ' + jQuery('#geomap_ddlCountry :selected').text();
      var options   = {zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP }
      var map       = new google.maps.Map(document.getElementById("map_canvas"), options);
      var geocoder  = new google.maps.Geocoder();

      //Center map for current selected city
      geocoder.geocode(    
      { 
        address: currentLocation}, function(results, status)
        {
            if (status == google.maps.GeocoderStatus.OK && results.length) {
                alert(results[0].geometry.location);
                map.set_center(results[0].geometry.location);
            } else 
            {
                var oslo = new google.maps.LatLng(59.9167, 10.75);
                map.set_center(oslo);
            } 
        }
      );  
    }
  }

【问题讨论】:

    标签: javascript geocoding google-maps google-maps-api-3


    【解决方案1】:

    Map 类中似乎没有set_center 方法;你应该改用setCenter

    【讨论】:

      猜你喜欢
      • 2022-01-02
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      相关资源
      最近更新 更多