Пример #1
0
 public function getAddressByLatLng($latitude, $longitude)
 {
     $url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' . $latitude . ',' . $longitude;
     $response = $this->sendRequest($url);
     $addresses = [];
     if ($this->gotResults($response)) {
         $results = $response['results'];
         foreach ($results as $result) {
             $addressArray = ['street' => str_replace('Dr', 'Drive', $this->getStreetFromComponents($result['address_components'])), 'city' => $this->getCityFromComponents($result['address_components']), 'state' => $this->getStateFromComponents($result['address_components']), 'country' => $this->getCountryFromComponents($result['address_components'])];
             $address = new Address($addressArray);
             $address->shortAddress = $this->buildCommaSeparatedStringFromArray($addressArray);
             $address->setLatitude($latitude)->setLongitude($longitude);
             $addresses[] = $address;
         }
     }
     return $addresses;
 }
Пример #2
0
<?php

require './vendor/autoload.php';
use DrawMyAttention\PHPAddressr\GoogleGeocode;
use DrawMyAttention\PHPAddressr\Address;
$geocode = new GoogleGeocode();
$address = new Address(['company' => 'Energy Aspects Ltd.', 'building' => '1 Dock Offices', 'street' => 'Surrey Quays Road', 'city' => 'London', 'postcode' => 'SE16 2XU', 'country' => 'United Kingdom']);
var_dump($geocode->getLatLng($address->toArray()));
$address = new \DrawMyAttention\PHPAddressr\Address(['company' => 'Energy Aspects Ltd.', 'street' => 'Surrey Quays Road', 'postcode' => 'SE16 2XU']);
var_dump($geocode->getLatLng($address->toArray()));
$latLng = $geocode->getLatLng(['street' => 'Surrey Quays Road', 'city' => 'London', 'postcode' => 'SE16 2XU']);
var_dump($latLng);
$address = $geocode->getFullAddressByPostcode('SE16 2XU');
var_dump($address);
Пример #3
0
 public function test_it_can_be_constructed_with_initial_values_and_default_required_values()
 {
     $address = new Address(['building' => 'Dock Offices', 'street' => 'Surrey Quays Road']);
     $this->assertEquals('Dock Offices', $address->building());
     $this->assertFalse($address->isRequired('building'));
     $this->assertEquals('Surrey Quays Road', $address->street());
     $this->assertTrue($address->isRequired('street'));
     $this->assertEquals('', $address->city());
     $this->assertTrue($address->isRequired('city'));
     $this->assertEquals('', $address->state());
     $this->assertFalse($address->isRequired('state'));
     $this->assertEquals('', $address->postcode());
     $this->assertTrue($address->isRequired('postcode'));
     $this->assertEquals('', $address->country());
     $this->assertTrue($address->isRequired('country'));
 }