Support the ongoing development of Laravel.io →
posted 8 years ago
Laravel.io
Last updated 2 years ago.
0

You really don't need to rewrite everything in that example. The xml part is unnecessary, you can do json.

You need a table (markers) with fields lat, long and store names. Then use the sql query mentioned in the tutorial above

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;

In Laravel you can just do a DB::raw(), then return as a json string. Then on the client side you need to write js to loop through the response and add each location on to the map.

Since you're using a lot of lat long related data consider using mongodb rather than mysql. In mongodb you can do the above query using this:

$km = 1; // 1 kilometer radius
$collection->find(['location'=> ['$nearSphere'=> [ $lng, $lat ], '$maxDistance'=> $km / 6371 ]])

https://docs.mongodb.org/v3.0/reference/operator/query/nearSphere/

Last updated 8 years ago.
0

I have now values for my lat and lng sir that I will be using in the query..I just want to ask how to output the data since it uses XML codes..how can i convert it to laravel

Last updated 8 years ago.
0

can you help me sir putting the code to laravel

0

Sign in to participate in this thread!

Eventy

Your banner here too?

boyjk23 boyjk23 Joined 4 Jan 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.