....未捕获TypeError:无法读取null的属性'__e3_'

时间:2016-09-27 07:27:19

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

我的错误是

  

Uncaught TypeError:无法读取null js的属性'__e3_'?v = 3.exp& key = AIzaSyDwehIgJvLsANnWEDppiUFr4Srk2G2M5IE& sensor = false& libraries = drawing,places:35

当我调查时,它会将我带到我的代码的这一部分

google.maps.event.addListenerOnce(map, 'tilesloaded', function () {

这是我的代码:

function initialize() {

           var mzansi = new google.maps.LatLng(-28.2751829172523, 25.0430317799304);
           var mapOptions = {
               center: mzansi,
               defaults: {
                   icon: 'red_dot.png',
                   shadow: 'dot_shadow.png',
                   editable: true,
                   strokeColor: '#990000',
                   fillColor: '#EEFFCC',
                   fillOpacity: 0.6
               },
               disableDefaultUI: true,
               mapTypeControl: true,
               mapTypeId: google.maps.MapTypeId.ROADMAP,
               mapTypeControlOptions: {
                   position: google.maps.ControlPosition.TOP_LEFT,
                   style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
               },
               panControl: false,
               streetViewControl: false,
               zoom: 6,
               zoomControl: true,
               zoomControlOptions: {
                   position: google.maps.ControlPosition.LEFT_TOP,
                   style: google.maps.ZoomControlStyle.SMALL
               }
           }


           $('#tabNavigationDiv').tabs({
               border: true,
               onSelect: function (value) {

                       switch (value) {
                           case "Subscription List":
                               selectedDayTab = 1;
                               if (SubscriptionMap == null) {
                                   SubscriptionMap = new google.maps.Map(document.getElementById('SubscriptionListMap'), mapOptions);
                               }
                               else {
                                   google.maps.event.trigger(SubscriptionMap, 'resize');
                               }

                               break;
                           case "Predefined Location List":
                               selectedDayTab = 2;
                               if (PredefinedMap == null) {
                                   PredefinedMap = new google.maps.Map(document.getElementById('PredefinedLocationListMap'), mapOptions);
                               }
                               else {
                                   google.maps.event.trigger(PredefinedMap, 'resize');
                               }

                               break;
                           case "Predefined Location":
                               selectedDayTab = 3;
                               if (map == null) {
                                   map = new google.maps.Map(document.getElementById('PredefinedLocationMap'), mapOptions);
                               }
                               else {
                                   google.maps.event.trigger(map, 'resize');
                               }

                               break;

                       }
               }
           }).tabs('tabs');


           google.maps.event.addListenerOnce(map, 'tilesloaded', function () {
               RSABounds = map.getBounds();
               console.log(RSABounds)

               $(searchLocation).autocomplete({
                   source: function (request, response) {

                       if (geocoder == null) {
                           geocoder = new google.maps.Geocoder();
                       }

                       geocoder.geocode({
                           'address': request.term, bounds: RSABounds
                       }, function (results, status) {
                           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
                                });*/


                               map.setZoom(20);

                               var searchLoc = results[0].geometry.location;
                               var lat = results[0].geometry.location.lat();
                               var lng = results[0].geometry.location.lng();
                               var latlng = new google.maps.LatLng(lat, lng);
                               var bounds = results[0].geometry.bounds;

                               geocoder.geocode({
                                   'latLng': latlng
                               }, function (results1, status1) {
                                   if (status1 == google.maps.GeocoderStatus.OK) {
                                       if (results1[1]) {
                                           response($.map(results1, function (loc) {
                                               return {
                                                   label: loc.formatted_address,
                                                   value: loc.formatted_address,
                                                   bounds: loc.geometry.bounds
                                               }
                                           }));
                                       }
                                   }
                               });
                           }
                       });
                   },
                   select: function (event, ui) {
                       var pos = ui.item.position;
                       var lct = ui.item.locType;
                       var bounds = ui.item.bounds;

                       if (bounds) {
                           map.fitBounds(bounds);
                       }
                   }
               });
           });

           //    searchBox = new google.maps.places.SearchBox(document.getElementById('description'));
           searchBox = new google.maps.places.SearchBox(document.getElementById('searchLocation'));

           google.maps.event.addListener(searchBox, 'places_changed', function () {
               searchBox.set('map', null);

               var places = searchBox.getPlaces();

               var bounds = new google.maps.LatLngBounds();
               var i, place;
               for (i = 0; place = places[i]; i++) {
                   (function (place) {
                       var marker = new google.maps.Marker({
                           position: place.geometry.location
                       });
                       var circle = new google.maps.Circle({
                           map: map,
                           radius: 16093,    // 10 miles in metres
                           fillColor: '#AA0000'
                       });
                       circle.bindTo('center', marker, 'position');
                       marker.bindTo('map', searchBox, 'map');
                       google.maps.event.addListener(marker, 'map_changed', function () {
                           if (!this.getMap()) {
                               this.unbindAll();
                           }
                       });
                       bounds.extend(place.geometry.location);

                   }(place));
               }
               map.fitBounds(bounds);
               searchBox.set('map', map);
               map.setZoom(Math.min(map.getZoom(), 12));

           });

           google.maps.event.addListener(map, 'tilesloaded', function () {

           });

           map.drawingManager = new google.maps.drawing.DrawingManager({
               drawingControlOptions: {
                   position: google.maps.ControlPosition.TOP_CENTER,
                   drawingModes: [
                    /* google.maps.drawing.OverlayType.MARKER,
                       google.maps.drawing.OverlayType.POLYLINE,
                       google.maps.drawing.OverlayType.POLYGON,*/
                       google.maps.drawing.OverlayType.RECTANGLE
                   ]
               },
               /* markerOptions: map.defaults,
                polygonOptions: map.defaults,
                polylineOptions: map.defaults,*/
               rectangleOptions: map.defaults

           });

           map.drawingManager.setMap(map);
           google.maps.event.addListener(map.drawingManager, 'overlaycomplete', function (event) {
               var wkt;

               //app.clearText();

               clearMap();
               arrayOverlays.push(event.overlay);

               wkt = new Wkt.Wkt();
               wkt.fromObject(event.overlay);

               var myGeometry = wkt.write();

               viewModel.location_geom(myGeometry);
               //  viewModel.radius(myGeometry);

               console.log(myGeometry);

           });

           }
       }

1 个答案:

答案 0 :(得分:1)

除非您点击开关案例“预定义位置”,否则代码中未定义map变量。因此,除非在这种情况下,它在生成错误的行中未定义(它将为null):

google.maps.event.addListenerOnce(map, 'tilesloaded', function ()