javascript - Returning getJSON result from nest function -


this question has answer here:

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

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -