'JSON Array to Javascript for use in a Mapkit JS map
Sorry if this is answered somewhere but I have genuinely looked everywhere. I'm pretty useless at Javascript, just can't wrap my head around it.
I've pulled information from my CRM's API run json_decode and the JSON array that looks like this.
Array
(
[parties] => Array
(
[0] => Array
(
[id] => 223456351
[owner] =>
[team] =>
[type] => organisation
[about] =>
[name] => ACME Inc
[createdAt] => 2022-03-15T14:10:46Z
[updatedAt] => 2022-04-01T13:58:35Z
[lastContactedAt] => 2022-03-15T14:19:11Z
[pictureURL] =>
[phoneNumbers] => Array
(
)
[addresses] => Array
(
[0] => Array
(
[id] => 49336420
[type] =>
[city] => New York
[country] =>
[street] => Broadway,
[state] =>
[zip] => 10004
)
)
[emailAddresses] => Array
(
)
[websites] => Array
(
)
)
[1] => Array
(
[id] => 226323207
[owner] =>
[team] =>
[type] => organisation
[about] =>
[name] => Wayne Enterprises
[createdAt] => 2022-02-08T14:21:35Z
[updatedAt] => 2022-04-01T14:01:19Z
[lastContactedAt] => 2022-02-08T15:56:59Z
[pictureURL] =>
[phoneNumbers] => Array
(
)
[addresses] => Array
(
[0] => Array
(
[id] => 493532394
[type] =>
[city] => New York
[country] =>
[street] => Broadway,
[state] =>
[zip] => 10004
)
)
[emailAddresses] => Array
(
)
[websites] => Array
(
)
)
I would like to cycle through the 'zip' field to make annotations in Mapkit JS like below. And this is where I'm stuck I cannot for the life of me work out how to use a foreach or similar or pull the information.
let geocoder = new mapkit.Geocoder();
geocoder.lookup("ZIPHERE", (error, data) => {
if (error) {
return;
}
map.addAnnotation(new mapkit.MarkerAnnotation(data.results[0].coordinate));
});
Any help would be amazing.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
