bootcamp-s18 / laravel-group-maker

0 stars 0 forks source link

Research options for using Google services to find lat/long for users #1

Open jhempy opened 6 years ago

rcbrowder commented 6 years ago

Not sure if this is exactly what is needed, but here is the Developer Guide for getting user location data using the Google Maps Geolocation API.

rcbrowder commented 6 years ago

Querying Locations "Near Me"

Once we have the location information of our participant we need search the locations of all groups and return the ones that are within a certain distance of the user. We could use a database query to achieve this using the code below as a starting point.

$circle_radius = 3959;
$max_distance = 20;
$lat = {your_lat};
$lng = {your_lng};

 return $groups = DB::select(
               'SELECT * FROM
                    (SELECT id, latitude, longitude, (' . $circle_radius . ' * acos(cos(radians(' . $lat . ')) * cos(radians(latitude)) *
                    cos(radians(longitude) - radians(' . $lng . ')) +
                    sin(radians(' . $lat . ')) * sin(radians(latitude))))
                    AS distance
                    FROM groups) AS distances
                WHERE distance < ' . $max_distance . '
                ORDER BY distance
                OFFSET 0
                LIMIT 20;
            ');

Reference

TheErikWolfe commented 6 years ago

This may help find 'Markers' in a specific range. I found google's geometry library which has good references on what Chris was describing.

I also found a good example provided by google on making a clothing store locator that uses the radius from where you are to find a store near you.