Hiking Project Logo

API/ free widgets


Original Post
Daniel Walz · · Conway, AR · Joined Jan 2019 · Points: 0

Hello, I just first want to say that I think this website is awesome and I want to thank ya for letting it be free. Also, I'm thankful for the API that is available so that I can use you all's data to build a web development project that I'm working on.

My goal is that I create an application that allows a user to type in a city/state or zip code and it returns all of the trails near by. Then the user is allowed to save the ones they like to their account.
Basically it will be a dumb down version of this website. I would love to be able to show a hiking area map of the search the user puts in. I saw that you all have free widgets and you have a hiking area map. "hikingproject.com/widget/ma…;location=fixed&x=-11720100&y=4865449&z=6.5&h=500" This is an url to one of you all's area maps. I don't want to hard code the area map into my code, so I was hoping if I interject dynamic variables into that url I would get back the desired area. I saw the arguments in the above url 'x=' and 'y='. I thought these variables were the latitude and longitude of the area but I have realized that is not the case. I realized the area map changes it output based on these values however I don't know what they represent.
Is there any way I can make the URL: "hikingproject.com/widget/ma…;location=fixed&x=-11720100&y=4865449&z=6.5&h=500" dynamic in my code if I was able to interpolate the users values?  

Thank you

Nick Wilder · · Boulder, CO · Joined Jan 2005 · Points: 5,723

x and y actually are like long and lat, so you can go that route by using the conversion functions below.

public static function lon2x($lon)
{
    $val = round(deg2rad($lon) * 6378137.0);
    if (is_nan($val)) {
        $val = 0;
    }

    return $val;
}

public static function lat2y($lat)
{
    $val = round(log(tan(M_PI_4 + deg2rad($lat) / 2.0)) * 6378137.0);
    if (is_nan($val)) {
        $val = 0;
    }

    return $val;
}

public static function x2lon($x, $precision = 8)
{
    $val = round(rad2deg($x / 6378137.0), $precision);
    if (is_nan($val)) {
        $val = 0;
    }

    return $val;
}

public static function y2lat($y, $precision = 8)
{
    $val = round(rad2deg(2.0 * atan(exp($y / 6378137.0)) - M_PI_2), $precision);
    if (is_nan($val)) {
        $val = 0;
    }

    return $val;
}

Daniel Walz · · Conway, AR · Joined Jan 2019 · Points: 0

Thank you so much

Guideline #1: Don't be a jerk.

Hiking Project Feedback & Suggestions
Post a Reply to "API/ free widgets"

Log In to Reply