2017-07-21 3 views
0

googleMaps API javascriptを使用していますが、それはうまくいきますが、ページをリロードしてブラウザのコンソールタップで例外が表示され、マップが表示されません。GoogleMapsがページロードで初期化されない

キャッチされないNC JSキー= MyAPIKey &コールバック= initMap:?98 私のjavascriptのコード:

<script async defer 
       src="https://maps.googleapis.com/maps/api/js?key=NyAPIKey&callback=initMap"> 
     </script> 

function initMap() { 
     if (typeof google === 'object' && typeof google.maps === 'object') { 
      // Create the map. 
      var map = new google.maps.Map(document.getElementById('googleapi'), { 
       zoom: 14, 
       center: { lat: @Model.SelectedAppliance.Lat, lng: @Model.SelectedAppliance.Lon }, 
       mapTypeId: 'terrain' 
      }); 

      var marker = new google.maps.Marker({ 
       position: map.center, 
       map: map, 
       title: 'Device Home' 
      }); 

      // Construct the circle for each value in citymap. 
      // Note: We scale the area of the circle based on the population. 
      var positionCircle = new google.maps.Circle({ 
       strokeColor: '#FF0000', 
       strokeOpacity: 0.8, 
       strokeWeight: 2, 
       fillColor: '#FF0000', 
       fillOpacity: 0.35, 
       map: map, 
       center: map.center, 
       radius: getMeters(@Model.SelectedAppliance.TriggerMile), 
      }); 

      return positionCircle; 
     } else { 
      window.location.reload(true); 
     } 

    } 

    function ContainPoint(device, lat, lon) { 
     if (typeof google === 'object' && typeof google.maps === 'object') { 
      markerCPosition = new google.maps.LatLng(lat, lon); 
      var circleBounds = initMap().getBounds(); 
      if (!circleBounds.contains(markerCPosition)) { 
       $(device).hide(true); 
      } 
     } else { 
      window.location.reload(true); 
     } 
    } 
+1

この機能は「

0

あなたは非同期を削除してみましたか?

+0

私はそれを試していない – beginerdeveloper

+0

非同期平均は何ですか? – beginerdeveloper

+1

非同期:タスクを非同期に実行すると、前のタスクが完了する前に別のタスクに直接切り替えることができます。 1つのタスクは他のタスクに依存しません。 さらに詳しい情報が必要な場合は、 https://stackoverflow.com/questions/748175/asynchronous-vs-synchronous-execution-what-does-it-really-mean –

関連する問題