JSON.stringify(this.p)
console.log(this.p + " " + typeof(this.p))
When I execute these commands, the output is:
[{lat:52.52193980072258,lng:13.401432037353516},{lat:52.52319316685915,lng:13.407096862792969},{lat:52.51969409696076,lng:13.407225608825684}] string
This indicates that this.p
is a string. However, when attempting to draw a polygon on my google map using this string, it results in an exception due to the expected data type being an Array.
How can I convert this string into an array (such as google.maps.LatLngLiteral or another compatible format)?
Please note: If I try to parse the string using JSON.parse(this.p)
:
JSON.parse(this.p)
console.log(this.p + " " + typeof( this.p))
I encounter the following error:
SyntaxError: Unexpected token l in JSON at position 2
What could be causing this issue and how can I resolve it?
The code snippet for utilizing this in my polygon is as follows:
var polygon = new google.maps.Polygon({
paths: this.p,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: '#FF0000',
fillOpacity: 0.35,
map: this.map
});