Created
March 9, 2017 11:04
-
-
Save anthonybudd/b451eea818646d77d783689f5f9a36d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class City extends WP_Model | |
{ | |
public $postType = 'city'; | |
public $attributes = [ | |
'latitude', | |
'longitude' | |
]; | |
public function saving($model){ | |
$output = json_decode(file_get_contents("http://maps.google.com/maps/api/geocode/json?address=". $model->title ."&sensor=false")); | |
$latitude = @$output->results[0]->geometry->location->lat; | |
$longitude = @$output->results[0]->geometry->location->lng; | |
if(!empty($latitude) && !empty($longitude)){ | |
$model->latitude = $latitude; | |
$model->longitude = $longitude; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment