Advertisement
Guest User

Afstand berekenen tussen postcodes

a guest
Sep 2nd, 2014
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Voor sitedeals leden
  2. ---------------------------
  3.  
  4. $postcode = '1234AB';
  5.  
  6. $this->data['googleapi']['url'] = 'http://maps.google.com/maps/api/geocode/xml?address='.urlencode($postcode.",Nederland").'&sensor=false';
  7. $this->data['xml'] = simplexml_load_file($this->data['googleapi']['url']);
  8. $this->data['coordinates'] = $this->data['xml']->result->geometry->location;
  9.  
  10. $this->data['lat'] = $this->data['coordinates']->lat;
  11. $this->data['lng'] = $this->data['coordinates']->lng;
  12.  
  13. $this->data['lat1'] = deg2rad(floatval($this->data['lat']));
  14. $this->data['lat2'] = deg2rad(floatval($result[0]['lat'])); //hier de lat van eerdere opgehaalde positie van andere postcode
  15. $this->data['lng1'] = deg2rad(floatval($this->data['lng']));
  16. $this->data['lng2'] = deg2rad(floatval($result[0]['lng'])); //hier de lng van eerdere opgehaalde positie van andere postcode
  17.  
  18. $this->data['earthradius'] = 6372.797; // mean radius of Earth in km
  19. $this->data['dlat'] = $this->data['lat2'] - $this->data['lat1'];
  20. $this->data['dlng'] = $this->data['lng2'] - $this->data['lng1'];
  21. $this->data['a'] = sin($this->data['dlat'] / 2) * sin($this->data['dlat'] / 2) + cos($this->data['lat1']) * cos($this->data['lat2']) * sin($this->data['dlng'] / 2) * sin($this->data['dlng'] / 2);
  22. $this->data['c'] = 2 * asin(min(1, sqrt($this->data['a'])));
  23. $this->data['afstand'] = $this->data['earthradius']* $this->data['c'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement