Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get longi and long with an adress react

// 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}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery attrib 
Javascript :: function listview list grud abnAlhaj 
Javascript :: creating hashblock method using sha256 hashing algorithm 
Javascript :: string to date with ist javascript 
Javascript :: Executing Code When Instance Is Created 
Javascript :: chrome page transitions 
Javascript :: React Using Self Made Module 
Javascript :: $faker randomElements 
Javascript :: Second Simplest Promise Example 
Javascript :: confirming the end javascript 
Javascript :: Captalize all words first letter javascript 
Javascript :: continuously update last updated time react js 
Javascript :: Error: Invalid route module file 
Javascript :: Hardhat deploy sample js code 
Javascript :: nestjs prisma controller 
Javascript :: how to check bot channel permissions 
Javascript :: mul function call to 3 functions 
Javascript :: Backbone Template 
Javascript :: get the first recurring character javascript 
Javascript :: convert milliseconds to seconds javascript 
Javascript :: how to convert javascript to typescript 
Javascript :: how to delete array filter in react hooks 
Javascript :: how to check the validation of time in react datetime 
Javascript :: change your favicon in javascript 
Javascript :: .reverse javascript string 
Javascript :: javascript number with commas 
Javascript :: how to check if input field has value 
Javascript :: nlhoman json load from file 
Javascript :: operadores de asignacion javascript 
Javascript :: javascript Access String Characters 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =