Answer the question
In order to leave comments, you need to log in
Problem with passing parameters to google maps?
Good afternoon, ladies and gentlemen.
I'm trying to create markers in a loop.
When you try to create an array with markers, it swears at
<Marker position={{ lat: {item.lat}, lng: {item.lng} }}>
, and specifically import React from 'react';
import {Map, GoogleApiWrapper, Marker} from "google-maps-react";
import markers from "./dataMarkers";
export class Maps extends React.Component {
constructor(props) {
super(props);
const markersComponent = markers.map((item) =>
<Marker position={{ lat: {item.lat}, lng: {item.lng} }}>);
}
render(){
const mapStyles = {
width: "100%",
height: "100%",
};
return (
<Map
google={this.props.google}
zoom={15}
style={mapStyles}
initialCenter={{ lat: 56.831719024772426, lng: 60.60158335488396 }}
>
{markersComponent }
</Map>
);
}
}
export default GoogleApiWrapper({
apiKey: '1111111111111111111111111111111'
})(Maps);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question