Having trouble converting text to numbers for geolocation coordinates. My model consists of a site with an ID and an array of points as a property. Rather than creating a relationship between site and points, I've structured it differently.
In my code:
points: Array<any> = [];
Rectangles is defined as an array of arrays:
rectangles: Array<Array<LatLngLiteral>> = [];
I am looping through sites for a specific customer, constructing the rectangles array to display on Google Maps. Each rectangle contains arrays representing the sites from the database. For example, if there are two sites, the rectangle array would look like this:
rectangles : [[
[
{"lat":44.841225,"lng":-0.580036},
{"lat":44.842236,"lng":-0.64696},
{"lat":44.805615,"lng":-0.63084}
],
[
{"lat":44.819868,"lng":-0.582811},
{"lat":44.853709,"lng":-0.483573},
{"lat":44.80696,"lng":-0.53299},
{"lat":44.80696,"lng":-0.629078}
]]]
The code snippet to retrieve this data is:
this.customerApi.getSites(this.currentUser.id)
.subscribe(response => {
this.sites = response;
this.rectangles.push(this.sites.map(s => s.points));
});
}
An example of the structure of a site object:
sites :
[
{
"siteName":"Site de Marseille",
"siteAdress1":"rue de blabla",
"siteAddress2":"string",
"siteCodPost":"13010",
"siteTown":"Marseille",
"points":
[
{"lat":44.841225,"lng":-0.580036},
{"lat":44.842236,"lng":-0.64696},
{"lat":44.805615,"lng":-0.63084}
],
"id":"5d0ce7c4a06b07213a87a753",
"companyId":"5cd430745304a21b9464a219",
"customerId":"5cd430c65304a21b9464a21a"
}
,
{
"siteName":"Site de Bordeaux",
"siteAdress1":"rue de la Garonne",
"siteAddress2":"string",
"siteCodPost":"31000",
"siteTown":"Bordeaux",
"points":
[
{"lat":44.819868,"lng":-0.582811},
{"lat":44.853709,"lng":-0.483573},
{"lat":44.80696,"lng":-0.53299},
{"lat":44.80696,"lng":-0.629078}
],
"id":"5d0cf65fa06b07213a87a754",
"companyId":"5cd430745304a21b9464a219",
"customerId":"5cd430c65304a21b9464a21a"}]
Need help figuring out the proper format for the rectangles array to correctly show rectangles on Google Maps. Maybe I need to adjust the number of square brackets due to the data format issue.
Tried using
points: Array<LatLngLiteral> = [];
but it didn't work. Uncertain about where or how to use parseFloat() method, if needed.
If you have any ideas or suggestions, please share!