Geolocation API Tutorial – Get User Location with Javascript

Published by Darron Toy on


hello and welcome to red stapler chanel
in this video we are going to show you how to detect user loccation using
geolocation API lots of websites today show a dynamic content based on users
location to provide relevant information such as advertisement or
local places nearby using geolocation is a pure JavaScript way
without any third-party services to retrieve accurate user location let’s
check it out the geolocation API allows JavaScript or web content to access the
user location or device’s location if you notice the pop-up notification on a
website asking you for permission to access your location
that’s the geolocation API since disclosing your location can compromise
your privacy web browsers will need your consent before they allow the
access using geolocation is very easy you can access to user position using
get current position and use the callback function to process the return
position object however some older browsers are not
supporting to your location so you should check it first just in case so here’s the return position object
looks like you can access to latitude and longitude of the user from position.coords.latitude and position.coords.longtitude now getting latitude and longitude is not very much useful so you need to reverse geocoding
to get the city country etc here’s the example of how to use Google Maps
reverse geocoding to get the address of specified coordinates and here’s the
return JSON of the address you can write a code to pass it and
extract a street address city country as you need or you can take the coordinates
and show it on Google Maps like this so that’s all for this video hope it
helps feel free to leave a comment if you have any questions and please feel
free to subscribe to our channel to stay tuned for updates if you love this
tutorial bye


16 Comments

Red Stapler · March 13, 2018 at 2:22 pm

Source code of this tutorial at: https://redstapler.co/detect-user-location-javascript/

Nitin mehra · April 6, 2018 at 8:14 am

getting errors in console of missing google api

KARTHICKRAJA M · June 21, 2018 at 3:19 am

Can I found geolocation of GIVEN mail id

PossessWithin · August 13, 2018 at 7:18 pm

Can I get a country's name with this method?

Anurag Patidar · November 3, 2018 at 5:40 pm

Can i get the css file ?

Joy Sen · January 5, 2019 at 7:11 am

Google does not support free api call anymore.

Digital Atul · February 13, 2019 at 6:43 am

how to see the location or that particular area or miles where a user used google map after on location?

RAAGHAV SHARMA · February 23, 2019 at 10:16 am

Is there way to not showing this pop up ?

waisullah yousofi · March 13, 2019 at 8:50 pm

copy$past

Youtube L · April 17, 2019 at 8:11 am

The location showing is from different city

Youtube L · April 17, 2019 at 8:12 am

if we use https connection, would it provide exact lat and long

YANIV SODAI · May 17, 2019 at 1:20 pm

whan you put the API of google on your website you dont need the put it between the IFRAM?
like in the youtube movie that you want to present on your web site?

Will Ward · June 19, 2019 at 2:02 am

Thanks! Is Red Stapler an Office Space reference?

ASIF ANDERSON · June 22, 2019 at 1:08 am

How can I use the form mentioned in this website

Flipclass.com

Hope to get positive response,
Regards,
Anderson from Karachi Pakistan
WhatsApp +923023005683

nuthouse99 · July 2, 2019 at 11:22 pm

Can you please explain how you pass the asynchronous call back position longitude and latitude to Google places API? Getting the the current location isn't very useful if you can't use those coordinates to find nearby places. How would you accomplish this through global variables? Please explain show an example any video? Would you use an await or promise?

Ishwar Chandra Tiwari · July 27, 2019 at 8:03 pm

Thanks you saved my day

Leave a Reply

Your email address will not be published. Required fields are marked *