src/Models/Address.php
public function geocode()
    {
        // build query string
        $query = [];
        $query[] = $this->street       ?: '';
        $query[] = $this->street_extra ?: '';
        $query[] = $this->city         ?: '';
        $query[] = $this->state        ?: '';
        $query[] = $this->post_code    ?: '';
        $query[] = $this->getCountry() ?: '';

        // build query string
        $query = trim(implode(',', array_filter($query)));
        $query = str_replace(' ', '+', $query);

        if (! $query)
            return $this;

        // build url
        $url = 'https://maps.google.com/maps/api/geocode/json?address='. $query .'&sensor=false';

        // try to get geo codes
        if ($geocode = file_get_contents($url)) {
            $output = json_decode($geocode);

            if (count($output->results) && isset($output->results[0])) {
                if ($geo = $output->results[0]->geometry) {
                    $this->lat = $geo->location->lat;
                    $this->lng = $geo->location->lng;
                }
            }
        }

        return $this;
    }
public function geocode()
    {
        // build query string
        $query = [];
        $query[] = $this->street       ?: '';
        $query[] = $this->street_extra ?: '';
        $query[] = $this->city         ?: '';
        $query[] = $this->state        ?: '';
        $query[] = $this->post_code    ?: '';
        $query[] = $this->getCountry() ?: '';

        // build query string
        $query = trim(implode(',', array_filter($query)));
        $query = str_replace(' ', '+', $query);

        if (! $query)
            return $this;

        // build url
        $url = 'https://maps.google.com/maps/api/geocode/json?address='. $query .'&sensor=false';

        // try to get geo codes
        if ($geocode = file_get_contents($url)) {
            $output = json_decode($geocode);

            if (count($output->results) && isset($output->results[0])) {
                if ($geo = $output->results[0]->geometry) {
                    $this->lat = $geo->location->lat;
                    $this->lng = $geo->location->lng;
                }
            }
        }

        return $this;
    }
public function geocode ( ) { // build query string $ query = [ ] ; $ query [ ] = $ this -> street ? : '' ; $ query [ ] = $ this -> street_extra ? : '' ; $ query [ ] = $ this -> city ? : '' ; $ query [ ] = $ this -> state ? : '' ; $ query [ ] = $ this -> post_code ? : '' ; $ query [ ] = $ this -> getCountry ( ) ? : '' ; // build query string $ query = trim ( implode ( ',' , array_filter ( $ query ) ) ) ; $ query = str_replace ( ' ' , '+' , $ query ) ; if ( ! $ query ) return $ this ; // build url $ url = 'https://maps.google.com/maps/api/geocode/json?address=' . $ query . '&sensor=false' ; // try to get geo codes if ( $ geocode = file_get_contents ( $ url ) ) { $ output = json_decode ( $ geocode ) ; if ( count ( $ output -> results ) && isset ( $ output -> results [ 0 ] ) ) { if ( $ geo = $ output -> results [ 0 ] -> geometry ) { $ this -> lat = $ geo -> location -> lat ; $ this -> lng = $ geo -> location -> lng ; } } } return $ this ; }
Try to fetch the coordinates from Google and store them.

@return $this
Try to fetch the coordinates from Google and store them .