<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Weyard Wiz</title>
    <description>The latest articles on DEV Community by Weyard Wiz (@weyardwiz).</description>
    <link>https://dev.to/weyardwiz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F842242%2F6f7ee960-e5db-476e-87fe-ce305e637fa7.png</url>
      <title>DEV Community: Weyard Wiz</title>
      <link>https://dev.to/weyardwiz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/weyardwiz"/>
    <language>en</language>
    <item>
      <title>Why are the marker positions not behaving correctly on map?</title>
      <dc:creator>Weyard Wiz</dc:creator>
      <pubDate>Tue, 05 Apr 2022 06:11:58 +0000</pubDate>
      <link>https://dev.to/weyardwiz/why-are-the-marker-positions-not-behaving-correctly-on-map-2pho</link>
      <guid>https://dev.to/weyardwiz/why-are-the-marker-positions-not-behaving-correctly-on-map-2pho</guid>
      <description>&lt;p&gt;I have the below JS code&lt;/p&gt;

&lt;p&gt;Why are only two markers displaying when clicking on the map, although the expectation is multiple markers should be displayed?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PY_tpN8H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8f0t31ougnpecffozj9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PY_tpN8H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8f0t31ougnpecffozj9.png" alt="map" width="880" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The marker is inside the tags too &lt;code&gt;&amp;lt;Marker key={i} position={latLng}&lt;/code&gt; so it should work properly... It seems that &lt;code&gt;{props.isMarkerShown &amp;amp;&amp;amp; &amp;lt;Marker position={props.markerPosition} /&amp;gt;}&lt;/code&gt; is not creating a new instance for the marker after the 2nd marker is created for some reason...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { compose, withStateHandlers } from "recompose";
import { InfoWindow, withGoogleMap, withScriptjs, GoogleMap, Marker } from 'react-google-maps';

const Map = compose(
    withStateHandlers(() =&amp;gt; ({
        isMarkerShown: false,
        markerPosition: null
      }), {
        onMapClick: ({ isMarkerShown }) =&amp;gt; (e) =&amp;gt; ({
            markerPosition: e.latLng,
            isMarkerShown:true
        })
      }),
    withScriptjs,
    withGoogleMap
)
    (props =&amp;gt;
        &amp;lt;GoogleMap
            defaultZoom={8}
            defaultCenter={{ lat: -34.397, lng: 150.644 }}
            onClick={props.onMapClick}
        &amp;gt;
            {props.isMarkerShown &amp;amp;&amp;amp; &amp;lt;Marker position={props.markerPosition} /&amp;gt;}

        &amp;lt;/GoogleMap&amp;gt;
    )

export default class MapContainer extends React.Component {
    constructor(props) {
        super(props)
    }

    render() {
        return (
            &amp;lt;div style={{ height: '100%' }}&amp;gt;
                &amp;lt;Map
                    googleMapURL="https://maps.googleapis.com/maps/api/js?key=AIzaSyCZ_nTRNVYtgm1qoelJ1nJ817OrNyG1JlA"
                    loadingElement={&amp;lt;div style={{ height: `100%` }} /&amp;gt;}
                    containerElement={&amp;lt;div style={{ height: `400px` }} /&amp;gt;}
                    mapElement={&amp;lt;div style={{ height: `100%` }} /&amp;gt;}
                /&amp;gt;
                {clicks.map((latLng, i) =&amp;gt; (
                    &amp;lt;Marker key={i} position={latLng} /&amp;gt;
                ))}
            &amp;lt;/div&amp;gt;
        )
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://developers.google.com/maps/documentation/javascript/react-map"&gt;https://developers.google.com/maps/documentation/javascript/react-map&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
