Getting google maps latlng Array from JSON

Getting google maps latlng Array from JSON

Dear forum-members,

I'm new to this forum and pretty new to JQuery and I have an issue that I can't solve by myself even after long research.

Currently I'm loading coordinates into an array directly in my html-file:

  1. var AreaCoords = [
  2. new google.maps.LatLng(48.250118898964146, 16.542320251464843),
  3. new google.maps.LatLng(48.25304504692614, 16.472831717692315),
  4. new google.maps.LatLng(48.20913525537747, 16.440147397806868),
  5. new google.maps.LatLng(48.190462182620756, 16.468437190633267),
  6. new google.maps.LatLng(48.18167250808985, 16.549736014567315),
  7. new google.maps.LatLng(48.21059952074874, 16.592033382039517)
  8. ]; 

With this variable, I'm later creating a google.maps.polygon:

  1. var Area = new google.maps.Polygon({
  2. paths: AreaCoords
  3. }); 

I know want to load the coordinates from a JSon file and I've thought about creating a JSON-File like this:

  1. {
  2. "coordinates": [
  3. {
  4. "lat": "48.250118898964146",
  5. "lng": "16.542320251464843"
  6. },
  7. {
  8. "lat": "48.25304504692614",
  9. "lng": "16.472831717692315"
  10. },
  11. {
  12. "lat": "48.20913525537747",
  13. "lng": "16.440147397806868"
  14. }
  15. ]
  16. }

I don't know how to load this JSON into a variable, I've tried the getJSON function but it didn't work at all.

I would appreciate any help or hint!

Thank you very very much!

-Robert