2016-11-03 343 views
0

我試圖把標記基於緯度和經度在谷歌地圖上存儲在我的Db。谷歌地圖不顯示地圖,並不顯示標記

但我沒有在我的頁面上查看地圖,也沒有標記。

無法弄清楚這裏有什麼問題。

我有console.log標記&結果是一個對象我不確定它是否應該如此。

@if (item.Longitude != null) 
    { 
     <span class="js-latmaps"> @item.Latitude</span> 
     <span class="js-longmaps"> @item.Longitude</span> 
    } 
    <div id="dvMap" style="width: 500px; height: 500px"> 
</div> 

@section scripts { 
    <script src="http://maps.google.com/maps/api/js?key=<"LONG_NUMBER">libraries = places"></script> 

<script type = "text/javascript"> 

     var markers = [ 
      { 
       "lat": $('.js-latmaps'), 
       "lng": $('.js-longmaps') 
      } 
     ]; 
     console.log(markers); 
     window.onload = function() { 
      var mapOptions = { 
       center: new window.google.maps.LatLng(markers[0].lat, markers[0].lng), 
       zoom: 8, 
       mapTypeId: window.google.maps.MapTypeId.ROADMAP 
      }; 
      var infoWindow = new window.google.maps.InfoWindow(); 
      var map = new window.google.maps.Map(document.getElementById("dvMap"), mapOptions); 
      for (var i = 0; i < markers.length; i++) { 
       var data = markers[i]; 
       var myLatlng = new window.google.maps.LatLng(data.lat, data.lng); 
       var marker = new window.google.maps.Marker({ 
        position: myLatlng, 
        map: map 

       }); 
       (function(marker, data) { 
        window.google.maps.event.addListener(marker, 
         "click", 
         function(e) { 
          infoWindow.setContent(data.description); 
          infoWindow.open(map, marker); 
         }); 
       })(marker, data); 
      } 
     }; 
    </script>} 

https://jsfiddle.net/9z6t2m3q/

+0

你得到什麼控制檯錯誤? –

+0

完全沒有錯誤 –

+0

將js小提琴添加到問題中。 –

回答

1

只需更換

<script src="http://maps.google.com/maps/api/js?key=<"LONG_NUMBER">libraries = places"></script> 

通過

<script src="https://maps.googleapis.com/maps/api/js?key=YOURKEY&libraries=places></script> 

請注意:

  • 要刪除<>在你API_KEY
  • 要添加API_KEY之間的&libraries=places
  • 要更換libraries = placeslibraries=places(無空格)
+0

<>僅用於q我的關鍵看起來像你寫的 –

+0

我也叫'maps.googleapis.com'而不是'maps.google.com'。你試過了嗎? – AlexB

+0

是的,這沒有幫助,如果我手動放置Lat \ Long數據就沒有問題。但是當我動態地發送它,然後看着控制檯.Log我c這個值在innerHTML「32.0609752」 innerText「32.0609752」,所以值是pas –