Member-only story
Google Maps API for postal code lookup — reverse geocoding
Requirement — Get the user postal code to localize content for the user
Step 1 : Get the Latitude and Longitude from your browser
getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(this.showPosition);
} else {
alert("Geolocation is not supported by this browser.");
}
}
showPosition(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
console.log("latitude : " + lat);
console.log("longitude : " + lng);
}
getCurrentPosition returns the current position while watchPosition API constantly tracks the current position of the user and returns the location like it was GPS tracked.
Step 2 :
Get Google Maps API key from your developer account :
If you have API from Google Cloud Platform for OAuth or any other service and enabled Geocoding API — It is NOT sufficient. Why ? Coz Google have all the maps services nested under Google Maps Platform.
As the message says, please create a new billing account particularly for “Google Maps Platform” and link it to a new Project for your Map Service needs and then enable Geocoding API to get the API key
https://console.cloud.google.com/apis/library/geocoding-backend.googleapis.com?q=Geocoding