[Plugin: MapPress Easy Google Maps] How to get geocoordinates out of Mappress Maps
-
I recently had an issue where I had to rework a page which already hat exisiting Mappress Maps.
What I needed there was the geocoordinates in order to calculate distances to other points
In case you need it here a the formulas for this
$maps = Mappress_Map::get_post_map_list($post->ID); //Get first map if (is_array($maps) && isset($maps[0])) { $lat = $maps[0]->pois[0]->point['lat']; $lng = $maps[0]->pois[0]->point['lng']; }
Calculating distance
function distance($lat1, $lng1, $lat2, $lng2, $miles = true) { $pi80 = M_PI / 180; $lat1 *= $pi80; $lng1 *= $pi80; $lat2 *= $pi80; $lng2 *= $pi80; $r = 6372.797; // mean radius of Earth in km $dlat = $lat2 - $lat1; $dlng = $lng2 - $lng1; $a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2); $c = 2 * atan2(sqrt($a), sqrt(1 - $a)); $km = $r * $c; return ($miles ? ($km * 0.621371192) : $km); }
calling function
echo round(distance($lat, $lng, 48.3534693, 11.7811621, false), 2).' Kilometers';
Hope this helps others!
(and also cudos to Chris Richardson who develops and maintains Mappress!)https://www.ads-software.com/extend/plugins/mappress-google-maps-for-wordpress/
- The topic ‘[Plugin: MapPress Easy Google Maps] How to get geocoordinates out of Mappress Maps’ is closed to new replies.