I am trying to make a basic heatmap using Google Maps API - https://developers.google.com/maps/documentation/javascript/heatmaplayer
I have an array of arrays of map coordinates I am passing from my rails controller like so:
@coordinates = [[51.60382, 0.02785], [51.6038, 0.02785], [51.60401, 0.02799], [51.60389, 0.02789], [51.60389, 0.02789], [51.60389, 0.02789], [51.60389, 0.02789], [51.60389, 0.02789], [51.60385, 0.02785], [51.60385, 0.02785], [51.60386, 0.02785], [51.60386, 0.02785], [51.60387, 0.02783], [51.60387, 0.02781]]
For each of these arrays I want to create a Google maps LatLng JavaScript object like so:
new google.maps.LatLng(37.782551, -122.445368),
I can get the array of coordinate arrays through to the view ok however am struggling to create an array of the objects that look like that above.
My most recent attempt:
var coordinatesArray = <%= @coordinates %>;
function getPoints() {
function coordinatesArrayTwo () {
var coordinatesArrayNew = coordinatesArray.map( c => new google.maps.LatLng(c[0], c[1]) );
return coordinatesArrayNew;
};
return[coordinatesArrayTwo()]
The idea being to iterate through the array of arrays and create a new object inserting the array coordinates...
However this does not seem to work and I am having a hard time viewing what it is actually returning.
I have a feeling it is fairly basic but could anyone help with this?
Thanks
var coordinatesArray = <%= @coordinates %>;is suspicious.visualization_impl.js:formatted:277 Uncaught (in promise) TypeError: b.lat is not a functionIs the only error I get in the console. Apparently this is due to the array being in the wrong format... I have tried .to_json and .html_safe on that@coordinatesarray too...