Get users current lat and longitude

This topic contains 5 replies, has 2 voices, and was last updated by  urbanfix 8 years, 8 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #53242

    urbanfix
    Expired Member
    Post count: 310

    Hi guys,
    I’m trying to build a function that, at the click of a button will add the users latitude and longitude to the end of a url, I was wondering what function i could use to echo the current users lat and lon?

    This is the kind of code im thinking..

    
    
    add_action('geodir_detail_page_sidebar' , 'foodnearme', 100);
    function foodnearme(){
    global $post, $wp_query, $geodirectory;
    
    $lat= geodir_get_user_latitude($??USER_latitude,'??USER_latitude',true); //lat
    $lon= geodir_get_user_longitude($??USER_longitude,'??USER_longitude',true); //lon
    //echo $e_add.$lat.$lon;
    
    echo "<div class='customfoodnearmebutton'><button><a href="http://urban-fix.co.uk/?geodir_search=1&s=+&snear=Near%3A+User+defined&sgeodir_cuisines%5B%5D=&sgeodir_musicgenre%5B%5D=&sort_by=&sgeo_lat=".$lat."&sgeo_lon=".$lon."" target="_blank"> Open Food and Drink Near You!</a></button></div>";
    }

    Any advice would be great!
    Thanks,
    UF

    #53278

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    there are no such functions : geodir_get_user_latitude and geodir_get_user_longitude.

    The only way to get user lat and long is by going through Google GeoLocation service and make a call to their API. It is more work than you’d expect.

    You’ll have to find a developer to help you implement this, if you want I can move the topic in the Jobs section of the forum.

    Let us know,

    Thank you

    #53282

    urbanfix
    Expired Member
    Post count: 310

    That makes sense, I was thinking it could be saved somewhere, but then obviously location results would be static!
    Dont move to jobs its okay,
    Please mark as resolved!
    Thanks,
    UF

    #57124

    urbanfix
    Expired Member
    Post count: 310

    Hi, I would just like to say i have found a simple html5 script (something to do with the browser) that will get the lat and longitude and echo it back, would anybody be able to pass it into a url for me if i provide the script?
    Thanks, UF

    #57126

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    if you want I can move this in the jobs forum.

    let me know,

    Thanks

    #57131

    urbanfix
    Expired Member
    Post count: 310

    No please leave it here, as im hoping someone else will pick this up.
    This would essentially create a category specific location/me page just by utilizing the existing GD set up..
    I’m sure most users would like to have the ability to allow there users to click a button and be taken to a category specific list of businesses ordered from nearest to farthest.
    I will add the script in the morning!
    Thanks, UF

Viewing 6 posts - 1 through 6 (of 6 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket