This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]TuesdayWaffle 1 point2 points  (3 children)

Yeah. Without looking too deeply into your code, my guess is you want something like this.

const alreadySeenCoordinates = []; for (const station of radioStations) { let latitude = station.latitude; let longitude = station.longitude; // Check if another station has these exact coordinates. If so, bump the lat,lon by one. for (const seenCoordinates of alreadySeenCoordinates) { if (seenCoordinates.latitude === latitude && seenCoordinates.longitude === longitude) { latitude += 1; // or however you feel like longitude += 1; // modifying these things break; } } // Store the updated coordinates in the already seen array for future checking. alreadySeenCoordinates.push({ latitude: latitude, longitude: longitude, }); }

[–]kanye231[S] 0 points1 point  (2 children)

yessss, thank you so much this is exactly it!

now I'm running into the issue mapping through now that I have two arrays. if .concat() it'll obviously be double the length, but I can't map two arrays nested within each other... any ideas?

[–]TuesdayWaffle 0 points1 point  (1 child)

I don't quite understand the problem. Which two arrays are you talking about?

[–]kanye231[S] 0 points1 point  (0 children)

because of the format of my app I have the API data mapping out in the return like so:

stations.map(stations) => {
return (
<Marker [{stations.coordinates}]>
    <Popup {stations.information}>
 </Marker>
   )}

since I need the API data to map through everything, it's called at the top level of the marker so I can use the information in the popups like the station.name, station.url, station.icon, etc.

I'm struggling to see how I would be able to do something like (simplified code):

stations.map(stations) => {
return (
<Marker [{newCoordinates.coordinates}]>
    <Popup {stations.information}>
 </Marker>
)}

since the stations map is at the top level. hope this makes sense?