Dapatkan Longi dan Long Dengan Adress Bereaksi

// install dependency with npm as seen below
2// npm install react-geocode
3
4// IMPORTANT - You will need to insert your Google Maps API on line 15 or this
5// will not work, click on the link below to get started with Google Maps Platform
6// https://developers.google.com/maps/gmp-get-started
7
8// Don't forget to upvote if this helped
9
10import React, { useState, useEffect } from 'react';
11import Geocode from 'react-geocode';
12
13export default function FindLatLong () {
14
15  Geocode.setApiKey('<YOUR API HERE>'); //Insert your Google Maps API here
16  Geocode.enableDebug();
17
18  var address = 'Area 51, NV, USA';
19
20  const [lat, setLat] = useState(0)
21  const [long, setLong] = useState(0)
22
23  useEffect(() => {
24    Geocode.fromAddress(address).then(
25      response => {
26        setLat(response.results[0].geometry.location.lat);
27        setLong(response.results[0].geometry.location.lng);
28      }
29    )}, []
30  )
31
32  return(
33    <div>
34      <p>Address: {address}</p>
35      <p>Lat: {lat}</p>
36      <p>long: {long}</p>
37    </div>
38  )
39}
Alessandro Ballabio