Javascript API TutorialsjQuery And Javascript Tutorials

Google Map API for finding location using Latitude, Longitude and name

Hi Guys, In this article you will learn how to use Google Map API for finding location using Latitude, Longitude and using Location Name. There are lots of ways to work with Google API for map.  Follow the steps carefully to work with API. 

Step 1 You need genuine API Key. For getting API visit https://console.developers.google.com/iam-admin/projects . Create your project and then select your project. You can now search for Google Map API . Enable API and copy API Key provided. (Remember Google API has limits to access it.)

Step 2 After getting API Key. Call map library on your web page using code below.

<script src="https://maps.googleapis.com/maps/api/js?key=<!--YOUR API KEY-->&callback=initMap" async defer></script>

Remember to replace <!–YOUR API KEY–> with your key.

After completing both steps you are now ready to work with  API.

Before starting you must know that we can find a location,place using their decimal values(latitude,longitude) and second using their exact address. All addresses are not listed in G-Map.

If a address is already exists in G-Maps then result will be like as below

Google Map API

If your address exists in Google Map then you can call Map Api Library using below code instead of above .

<script src="https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY" async defer>
</script>

Above method is called as G-Maps Geocode. In this method whatever location you will enter it will be converted to a decimal longitude and decimal latitude value.

Reverse Geocode method is also available in which we enter decimal values and it is converted to String. If a location is not exist in Google Map then Geocode and Reverse Geocode API will return nearby places or return no value.

If your address does not exists then first find out exactly your location latitude and longitude values using  G-Maps you can visit url for finding Latitude and longitude values

https://www.google.com/maps?q=Place Name

After discover latitude and longitude values then call Google Map API Library as follow

<script src="https://maps.googleapis.com/maps/api/geocode/json?latlng=<!--LAT VALUE-->,<!--LONG VALUE-->&key=YOUR_API_KEY" async defer>
</script>

Replace <!–LAT VALUE–>,<!–LONG VALUE–> with your latitude, longitude value don’t remove , between latitude and longitude value.

These are the ways to find location using Google Maps API.

<a href=”https://www.devildoxx.com/blog/jquery-and-javascript-tutorials/how-to-hang-a-marker-in-google-map-api/”>How to embed market using Google Map API?</a>

Anil Mehra

I am Anil Mehra, a passionate, workaholic and a Full Stack Tech Savvy Programmer with true north towards growth. I have worked on 256 live projects in MNC. I am expertise in the field of Programming, Server Management, SEO, Blogging and SMO...

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button

Adblock Detected

Please turn off Ad blocker to view website