Skip to content

Instantly share code, notes, and snippets.

@Deviad
Last active May 10, 2020 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deviad/2b31714cd20c27aa60747bae03cebb13 to your computer and use it in GitHub Desktop.
Save Deviad/2b31714cd20c27aa60747bae03cebb13 to your computer and use it in GitHub Desktop.
google-maps-react not working
import React, {useState} from 'react';
import {GoogleAPI, GoogleApiWrapper, Map, Marker} from 'google-maps-react'
import {render} from "react-dom";
interface MapContainerProps {
google: GoogleAPI;
}
type MarkerEntry = { key: string, title: string, name: string, position: { lat: number, lng: number } };
const markers: MarkerEntry[] = [
{key: "1", title: "Title1", name: "Name1", position: {lat: 37.778519, lng: -122.405640}},
{key: "2", title: "Title2", name: "Name2", position: {lat: 37.759703, lng: -122.428093}},
{key: "3", title: "Title3", name: "Name3", position: {lat: 37.762391, lng: -122.439192}},
]
class MapContainer extends React.Component<any, any> {
renderMarkers = (markers: MarkerEntry[]) => {
return markers.map(m => (
<Marker>
key={m.key}
title={m.title}
position={m.position}
name={m.name}
</Marker>
));
}
render(){
if(google) {
return (
<Map google={google} zoom={14}>
{this.renderMarkers(markers)}
</Map>
)
}
return null;
}
}
export default GoogleApiWrapper({
//TODO: replace with public key api
apiKey: ""
})(MapContainer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment