簡體   English   中英

Google Maps API - 標記未顯示外部JSON

[英]Google Maps API - Markers not showing up from external JSON

我正在嘗試使用Google Maps API顯示許多多個地圖標記,數據位於外部JSON文件中的一系列數組中。

相關HTML / Javascript的片段

 <div id="map_canvas" style="width:100%; height:100%"></div> <script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript"> var map; function initialize() { var mapOptions = { center: new google.maps.LatLng(40.8039941, -77.863459), zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); } //get JSON data $(document).ready(function() { $.getJSON("crime_maps_test.json", function(json1) { $.each(json1, function(key, data) { var latLng = new google.maps.LatLng(data.lat, data.lng); // Creating a marker and putting it on the map var marker = new google.maps.Marker({ position: latLng, title: data.Incident }); marker.setMap(map); }); }); }); </script> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=API_key&callback=initialize"></script> 

crime_maps_test.json片段(實際文件包含幾百個數組)

 [ { "Incident": "PSU201701139" ,"Occurred": "3/25/17 23:25" ,"reported": "3/25/17 23:25" ,"nature of incident": "Resident Assistant reported the odor of marijuana, origin not located" ,"offenses": "Possession of Small Amount of Marijuana" ,"location": "Porter Hall" ,"disposition": "Open" ,"lat": 40.8008254 ,"lng": -77.8587917 }, { "Incident": "PSU201701136" ,"Occurred": "03/25/2017 9:25 PM to 9:30 PM" ,"reported": "3/25/17 21:31" ,"nature of incident": "Visitor observed highly intoxicated" ,"offenses": "Public Drunkenness" ,"location": "Bryce Jordan Center" ,"disposition": "Open" ,"lat": 40.8086228 ,"lng": -77.8642905 }, { "Incident": "PSU201701134" ,"Occurred": "03/25/2017 8:52 PM to 8:58 PM" ,"reported": "3/25/17 20:58" ,"nature of incident": "Resident Assistant reported the odor of marijuana, origin not located" ,"offenses": "Possession of Small Amount of Marijuana" ,"location": "Curtin Hall 5Th Floor" ,"disposition": "Open" ,"lat": 40.8051407 ,"lng": -77.8633569 } ] 

我在GitHub上托管項目以避免交叉引用錯誤。 當地圖顯示且開發人員的工具控制台未記錄任何錯誤時,標記不會顯示。 我在代碼中遺漏了一些阻止標記顯示的內容嗎? 有誰知道是什么導致了這個問題?

事實證明,有幾個JSON條目存在問題。 應該驗證數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM