javascript - Returning getJSON result from nest function -
this question has answer here:
- how return response asynchronous call? 21 answers
i converttolat() function return variable lat nested function. have tried many ways can't seem work. appreciated. thank you.
function converttolat(postal_code) { $.getjson("http://maps.googleapis.com/maps/api/geocode/json?address=" + postal_code, function(result){ var lat = result.results[0].geometry.location.lat; return lat; }); return function(); }
use below snippet
converttolat("211011").then(function(result){ var lat = result.results[0].geometry.location.lat; console.log(lat); }); function converttolat(postal_code){ return $.getjson("http://maps.googleapis.com/maps/api/geocode/json?address="+postal_code); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Comments
Post a Comment