Как разобрать файл geojson
Привет,
Я должен разобрать файл geojson на java/javascript и поместить координату на google maps.
Моя проблема заключается в том, чтобы разобрать файл.
Кто-нибудь может мне помочь?
Ниже я разместил часть файла.
Большое спасибо.
{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::4326"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "Polygon", "coordinates": [[[9.0114910478323, 45.35880131440966], [9.014491488013135, 45.35880097314403], [9.0144909480813, 45.35668565341486], [9.011490619692509, 45.356685994655464], [9.0114910478323, 45.35880131440966]]]}, "type": "Feature", "id": 0, "properties": {"cellId": 1}}, {"geometry": {"type": "Polygon", "coordinates": [[[9.014491488013135, 45.35880097314403], [9.017491928134044, 45.358800553060284], [9.017491276410173, 45.35668523336193], [9.0144909480813, 45.35668565341486], [9.014491488013135, 45.35880097314403]]]}, "type": "Feature", "id": 1, "properties": {"cellId": 2}}, {"geometry": {"type": "Polygon", "coordinates": [[[9.017491928134044, 45.358800553060284], [9.02049236818262, 45.35880005415845], [9.020491604666724, 45.356684734496675], [9.017491276410173, 45.35668523336193], [9.017491928134044, 45.358800553060284]]]}, "type": "Feature", "id": 2, "properties": {"cellId": 3}}, {"geometry": {"type": "Polygon", "coordinates": [[[9.02049236818262, 45.35880005415845], [9.023492808146456, 45.35879947643852], [9.023491932838542, 45.35668415681913], [9.020491604666724, 45.356684734496675], [9.02049236818262, 45.35880005415845]]]}, "type": "Feature", "id": 3, "properties": {"cellId": 4}}, {"geometry": {"type": "Polygon", "coordinates": [[[9.023492808146456, 45.35879947643852], [9.026493248013145, 45.35879881990051], [9.02649226091323, 45.35668350032926], [9.023491932838542, 45.35668415681913], [9.023492808146456, 45.35879947643852]]]}, ......Что я уже пробовал:
у меня было бы что-то вроде этого:
(этот пример работает, но он отличается от исходного файла)
<!DOCTYPE html>
<html>
<head>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</head>
<body>
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: new google.maps.LatLng(2.8,-187.3),
mapTypeId: 'terrain'
});
// Create a <script> tag and set the USGS URL as the source.
var script = document.createElement('script');
// This example uses a local copy of the GeoJSON stored at
// http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp
script.src = 'https://developers.google.com/maps/documentation/javascript/examples/json/earthquake_GeoJSONP.js';
document.getElementsByTagName('head')[0].appendChild(script);
}
// Loop through the results array and place a marker for each
// set of coordinates.
window.eqfeed_callback = function(results) {
for (var i = 0; i < results.features.length; i++) {
var coords = results.features[i].geometry.coordinates;
var latLng = new google.maps.LatLng(coords[1],coords[0]);
var marker = new google.maps.Marker({
position: latLng,
map: map
});
}
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC48RmJ9oeHDnU3CkggNiR7T4tbKeVEiUU&callback=initMap">
</script>
</body>
</html>