JSFiddle - React, Tailwind, and code Playground
by Amitabha Ghosh
HTML
<input type=”text” name=”location” id=”location” />
<button id=”show-add” >Submit</button>
JavaScript
$(‘#show-add’).click(function(){
var location = $(‘#location’).val();
getAddress(location);
});
function getAddress(location){
geocoder = new google.maps.Geocoder();
geocoder.geocode( { ‘address’: location }, function(results, status) {
if (status == ‘OK’) {
alert(results[0].formatted_address);
} else {
alert(“Geocode was not successful for the following reason: ” + status);
}
});
}
function getAddress(location){
$.getJSON(“https://maps.googleapis.com/maps/api/geocode/json?address"+ location +"&key=AIzaSyDIprp-1kMZJbATA0O9uqReEvr8N82Ujik",function(data, textStatus){
$.each(data.Placemark, function(key, val) {
alert(val.address);
});
});
}