0

Hello i want to return latitude and longitude of my current position from a function i tried the following method to accomplish it,But it doesn't return any value. Do you have any alternate method?. Please help me out..

here is some part from my code...

     //calling the function
    var myloc=current_location();
    alert(myloc.lat1);

    function current_location(){
    var my_loc = {};
    navigator.geolocation.getCurrentPosition(function(position) {
    var geocoder = new google.maps.Geocoder();
    pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    var lat1=position.coords.latitude;
    var lon1=position.coords.longitude;
     my_loc.lat1 =lat1;
     my_loc.lon1 =lon1;
    });
    return my_loc;
    }
Sharan Rai
  • 94
  • 8
  • 1
    You can't return an async value from the calling function. The asynchronous operation has not completed when the function returns. See the question this is marked a dup of for the options you have (which all involve writing asynchronous-aware code, not synchronous code). – jfriend00 Jun 20 '15 at 05:55
  • @jfriend00 . Igot it .. – Sharan Rai Jun 20 '15 at 07:55

0 Answers0