未捕获的类型错误无法读取Mac上未定义的Google地图的属性“纬度”

时间:2014-08-07 00:44:10

标签: javascript macos google-maps

我正在我的网站上进行谷歌地图集成,这对我在Windows * Chrome和Firefox以及我的Android浏览器上工作,但我在OSX中仅在纬度上获得了未捕获的类型错误。这是我的代码:

var lat = '44.519';
var lon = '-88.019'; 
var latlong = readCookie('zblatlong');
if (latlong) {
    var res = latlong.split(",");
    var lat = res[0];
    var lon = res[1];
} else {
        if (google.loader.ClientLocation) {
            var loc = google.loader.ClientLocation;
       }
       if (loc.latitude){
            var lat = loc.latitude;
       }
       if (loc.longitude){
            var lon = loc.longitude;
       }
    createCookie('zblatlong',lat+','+lon,30);
}
console.log(lat);
console.log(lon);

var geocoder;
var map, layer;

function initialize() {
       geocoder = new google.maps.Geocoder();
       console.dir(geocoder);
       var styles = [
                 {
                   "stylers": [
                     { "invert_lightness": true },
                     { "saturation": -100 },
                     { "gamma": 1 },
                     { "lightness": 11 }
                   ]
                 },{
                   "featureType": "water",
                   "stylers": [
                     { "lightness": -100 }
                   ]
                 }];
       var mapOptions = {
         center: new google.maps.LatLng(lat, lon),
         zoom: 6,
         mapTypeId: google.maps.MapTypeId.ROADMAP,
         styles: styles
       };     
       map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
       var layer = new google.maps.FusionTablesLayer({
          query: {
            select: 'latitude',
            from: 'tableid'
          },
          map: map,
          styleId: 2,
          templateId: 3
        });

  layer.setMap(map);


     }
     google.maps.event.addDomListener(window, 'load', initialize);


function changeLocation(){
    var location = jQuery('#modal1 #address').val();
    geocoder.geocode( { 'address': location}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        var lat = results[0].geometry.location.lat();
        var lon = results[0].geometry.location.lng();
        createCookie('zblatlong',lat+','+lon,30);
        var location = new google.maps.LatLng(lat, lon);
        map.setCenter(location);
        console.log(lat);
        console.log(lon);
    } else {
      console.log('Geocode was not successful for the following reason: ' + status);
    }
  });
}


function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

HTML:

<div id="map_canvas"></div>
                   <div class="medium metro btn default locChange"><a href="#" id="change-location" class="switch" gumby-trigger="#modal1"><i class="icon-location"></i> Change My Location</a></div>

脚本在文档的头部被调用,所以我尝试将它移动到页脚而没有运气。我在新版本的Mac上看过一些关于Google Maps / Geolocation问题的帖子,但没有关于如何让它工作的解决方案。我用JSLint检查了我的代码,一切似乎都没问题。对你来说有什么可能是个问题吗?

0 个答案:

没有答案