Why do I get “map.set_center is not a function”?

a 夏天 提交于 2019-12-24 03:44:15

问题


This code have been working until I updated last night.
The code works perfectly on my localhost, but I get an error on my test server. The error message (from Firebug) is "map.set_center is not a function".

So why is this not working on my server any more?

  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);
            } 
        }
      );  
    }
  }

回答1:


It seems there is no set_center method in the Map class ; you should probably use setCenter, instead.



来源:https://stackoverflow.com/questions/1906970/why-do-i-get-map-set-center-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!