javascript - get latitude and longitude using ajax jasonp -
i try latitude , longitude using ajax jasonp.
this:-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> <script> $(document).ready(function(){ var region = "rajkot,jamnagar"; var cn ="in"; var lat; var lng; var array = region.split(','); var lat = new array(), lng = new array(); var totallength = array.length; var count = 0; for(var item in array) { $.ajax({ url: "http://services.gisgraphy.com//geocoding/geocode?address="+array[item]+"&country="+cn+"&format=json", async: false, datatype:'jsonp', success: function(data){ count++; lat.push(data.result[0].lat); lng.push(data.result[0].lng); if (count == totallength) { var commaseperatedlat = lat.tostring(); localstorage.setitem("newlat",commaseperatedlat); var commaseperatedlong = lng.tostring(); console.log(commaseperatedlat); } } }); } function all() { var moodle_groups_id = (localstorage.getitem("newlat")); alert(moodle_groups_id); } }); </script> <body> <input type="button" value="ok" onclick="all()"></input> </body>
i getting latitude , longitude.
want there variable when click on button/
use localstorage.setitem , getitem.
please me solve this.
thanks.
you need pass function all() outside of $(document).ready(function() function ;)
<script> $(document).ready(function(){ var region = "rajkot,jamnagar"; var cn ="in"; var lat; var lng; var array = region.split(','); var lat = new array(), lng = new array(); var totallength = array.length; var count = 0; for(var item in array) { $.ajax({ url: "http://services.gisgraphy.com//geocoding/geocode?address="+array[item]+"&country="+cn+"&format=json", async: false, datatype:'jsonp', success: function(data){ count++; lat.push(data.result[0].lat); lng.push(data.result[0].lng); if (count == totallength) { var commaseperatedlat = lat.tostring(); localstorage.setitem("newlat",commaseperatedlat); var commaseperatedlong = lng.tostring(); console.log(commaseperatedlat); } } }); } }); function all() { var moodle_groups_id = (localstorage.getitem("newlat")); alert(moodle_groups_id); } </script>
Comments
Post a Comment