Skip to content

Instantly share code, notes, and snippets.

@arsan-irianto
Last active March 15, 2019 00:04
Show Gist options
  • Save arsan-irianto/d164208f3515da00fb99220280cb6caf to your computer and use it in GitHub Desktop.
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
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