Last active
March 15, 2019 00:04
-
-
Save arsan-irianto/d164208f3515da00fb99220280cb6caf to your computer and use it in GitHub Desktop.
This script used to try integrating ReactJs with pure Google Maps API with following tutorial from here -> https://bit.ly/2UCz0HS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component, Fragment } from "react"; | |
import "./App.css"; | |
class App extends Component { | |
componentDidMount() { | |
this.renderMap(); | |
} | |
renderMap = () => { | |
loadScript( | |
"https://maps.googleapis.com/maps/api/js?key=AIzaSyBNeksjt_QfncrS2CAgbajesDOvw02ulOs&callback=initMap" | |
); | |
window.initMap = this.initMap; | |
}; | |
initMap = () => { | |
new window.google.maps.Map(document.getElementById("map"), { | |
center: { lat: -34.397, lng: 150.644 }, | |
zoom: 8 | |
}); | |
}; | |
render() { | |
return ( | |
<Fragment> | |
<h1>Simple Map</h1> | |
<div id="map" /> | |
</Fragment> | |
); | |
} | |
} | |
function loadScript(url) { | |
var index = window.document.getElementsByTagName("script")[0]; | |
var script = window.document.createElement("script"); | |
script.src = url; | |
script.async = true; | |
script.defer = true; | |
index.parentNode.insertBefore(script, index); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment