Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter('pods_api_pre_save_pod_item_life_groups', 'google_geo', 10, 2);
- function google_geo($pieces, $is_new_item) {
- // get the address values
- $address1 = $pieces['fields']['meeting_location_address_line_1']['value'];
- $address2 = $pieces['fields']['meeting_location_address_line_2']['value'];
- $city = $pieces['fields']['meeting_location_city']['value'];
- $zip = $pieces['fields']['meeting_location_zip_code']['value'];
- $badstrings = array (" ","'","-","<br>"); // strings we shouldn't pass in the url
- $goodstrings = array ("+","",",",""); // strings we are going to replace them with
- $nice_address1 = str_replace($badstrings,$goodstrings,$address1);
- $nice_address2 = str_replace($badstrings,$goodstrings,$address2);
- $nice_city = str_replace($badstrings,$goodstrings,$city);
- $nice_zip = str_replace($badstrings,$goodstrings,$zip);
- $url = $nice_address1.",".$nice_addres2.",".$nice_city.",".$nice_zip;
- $niceurl = strtolower($url);
- $geourl = "http://maps.google.com/maps/api/geocode/json?address=".$niceurl."&sensor=false";
- $geoinfo = file_get_contents($geourl);
- $decoded = json_decode($geoinfo);
- if ($decoded->status == "OK") :
- $pieces['fields']['latitude']['value'] = $decoded->results[0]->geometry->location->lat; // copy lat into the field called lat in your pod
- $pieces['fields']['longitude']['value'] = $decoded->results[0]->geometry->location->lng; // copy long into the field called long in your pod
- endif;
- podsDebugger::log_debug_data(print_r($pieces, TRUE));
- return $pieces;
- }
Add Comment
Please, Sign In to add comment