Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps - addGeoJson is not working for my file

addGeoJson is not working in google map for my file

please check below code that I am using in javascript

//create the map
map = new google.maps.Map(document.getElementById('map-canvas'), {
   zoom: 6,
   center: {lat:49.79, lng: -8.82}
});

// Load GeoJSON.
var promise = $.getJSON("Sensitive_Areas_Nitrates_Rivers.json"); //same as map.data.loadGeoJson();
promise.then(function(data){
    cachedGeoJson = data; //save the geojson in case we want to update its values
    console.log(cachedGeoJson);
    map.data.addGeoJson(cachedGeoJson,{idPropertyName:"id"});  
});

I have downloaded this file from here

you can check my JSON file Sensitive_Areas_Nitrates_Rivers.json

also, you can check this link with polygon

I have used below JSON format so you can check it

{ "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "EPSG:27700" } }, "features": [ { "type": "Feature", "id": 1, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 500051.6875, 224280.03130000085 ], [ 500047.2812999999, 224277.6875 ], [ 499977.5937999999, 224242.625 ], [ 499976.6875, 224242.21880000085 ] ] ] }, "properties": { "OBJECTID": 8, "type_of_sa": "SA_N", "datedesign": 1025136000000, "name": "Rivers Itchen", "length_km": 12, "uwwtd_code": "UKENRI134", "shape_Length": 12172.080443901654 } } ] }

[500051.6875, 224280.03130000085] - [X, Y] coordinates may be in EPSG: 27700 to EPSG:4326, Now we need to display these coordinates on google map, Is there any solution for this?

like image 402
Jaydeep Dhameliya Avatar asked Dec 27 '19 14:12

Jaydeep Dhameliya


People also ask

How do I load a GeoJSON file into Google Maps?

With the Data layer, you can add GeoJSON data to a Google map in just one line of code. map. data. loadGeoJson('google.

How do I open a JSON file in Google Maps?

Step 1: Please navigate to the “WP MAPS PRO -> JSON File To Map”. Step 2: Please select your map from the given 'Select Map' dropdown to add locations on a map.

Does Google Maps use GeoJSON?

Google Maps Platform supports GeoJSON data with a single function call.

How do I open a GeoJSON file?

If you have a geojson file on your local hard drive or network and want to view/use it in QGIS, you can just drag and drop it from the Browser Panel into the Layers Panel or just double click on the file will add it to the Layers Panel.


2 Answers

Since Google Maps expects GeoJSON to be in EPSG:4326, Sensitive_Areas_Nitrates_Rivers.json needs to be reprojected. QGIS, for instance, could be utilized for that matter (refer docs for a details)

enter image description here

enter image description here

Reprojected Sensitive_Areas_Nitrates_Rivers.json layer will be displayed like this:

enter image description here

like image 52
Vadim Gremyachev Avatar answered Oct 31 '22 05:10

Vadim Gremyachev


You are getting coordinates in metres. For displaying in google map you need to convert it into [Lng, Lat].

For converting metres to [Lng, Lat] you need to change the projection from EPSG: 27700 to 4326 then only you are able to get this geojson in [Lng, Lat]

Tool you can use: QGIS Desktop 3.4.14 Link: https://qgis.org/en/site/forusers/download.html

After convert you need to export this file as feature.

like image 29
Shivam Avatar answered Oct 31 '22 05:10

Shivam