Skip to content Skip to sidebar Skip to footer

List Events On Defined Area Using Google Maps

I have Google Map with defined a lot of events etc. How I can list all events eg. in 50km around my location?

Solution 1:

Since your question is a bit vague, I assume you have a list of lat, long coordinates. You can get them out of SQL using something like this:

SELECT 
z.id AS z__id, 
z.zipcode AS z__zipcode, 
z.city AS z__city, 
z.state AS z__state, 
z.county AS z__county, 
z.zip_class AS z__zip_class, 
z.latitude AS z__latitude, 
z.longitude AS z__longitude, 
((ACOS(SIN(* PI() /180) *SIN(z.latitude * PI() /180) +COS(* PI() /180) *COS(z.latitude * PI() /180) *COS((- z.longitude) * PI() /180)) *180/ PI()) *60*1.1515) AS z__0, 
((ACOS(SIN(* PI() /180) *SIN(z.latitude * PI() /180) +COS(* PI() /180) *COS(z.latitude * PI() /180) *COS((- z.longitude) * PI() /180)) *180/ PI()) *60*1.1515*1.609344) AS z__1 
FROM zipcode z 
WHERE z.city != ? 
ORDERBY z__0 asc 
LIMIT 50

z_0 will be the dinstance in miles, whereas z_1 will be the distance in km.

(source: http://www.doctrine-project.org/projects/orm/1.2/docs/manual/behaviors/en#core-behaviors:geographical)

Or use something like this (similar in php):

function distance($lat1, $lon1, $lat2, $lon2, $unit) { 

  $theta = $lon1 - $lon2; 
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
  $dist = acos($dist); 
  $dist = rad2deg($dist); 
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == "K") {
    return ($miles * 1.609344); 
  } elseif ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}

http://www.zipcodeworld.com/samples/distance.php.html

Post a Comment for "List Events On Defined Area Using Google Maps"