JSFiddle - React, Tailwind, and code Playground
by Alex Azuero
HTML
<h3>Geocoding without geocoder</h3>
<p>Location Name: <input><button>Get lat/lng</button><p>
<p id="wholeAddress"></p>
<p id="latlong"></p>
JavaScript
var apiURL = "http://maps.googleapis.com/maps/api/geocode/json?address=";
// $.getJSON() is a jQuery method that can replace the ajaxRequest() from AM1
$("button").click(function(){
var address = $("input").val();
$.getJSON(apiURL+encodeURI(address),
showResult)
});
// callback function
function showResult(response){
console.log("response from API ", response);
if (response.status == "OK") {
$("#wholeAddress").text(response.results[0].formatted_address);
var locObj = response.results[0].geometry.location;
$("#latlong").text(locObj.lat + "; " + locObj.lng);
}
}