create address from google address components

@return Coordinates
541169
public function createCoordinatesFromGeometry() : Coordinates
    {
        // create new coordinates object
        $coordinates = new Coordinates($this->googleData->geometry->location->lat, $this->googleData->geometry->location->lng);

        return $coordinates;
    }
1243624
function(result){

      var data = {},
        geometry = result.geometry,
        viewport = geometry.viewport,
        bounds = geometry.bounds;

      // Create a simplified version of the address components.
      $.each(result.address_components, function(index, object){
        var name = object.types[0];

        $.each(object.types, function(index, name){
          data[name] = object.long_name;
          data[name + "_short"] = object.short_name;
        });
      });

      // Add properties of the places details.
      $.each(placesDetails, function(index, key){
        data[key] = result[key];
      });

      // Add infos about the address and geometry.
      $.extend(data, {
        formatted_address: result.formatted_address,
        location_type: geometry.location_type || "PLACES",
        viewport: viewport,
        bounds: bounds,
        location: geometry.location,
        lat: geometry.location.lat(),
        lng: geometry.location.lng()
      });

      // Set the values for all details.
      $.each(this.details, $.proxy(function(key, $detail){
        var value = data[key];
        this.setDetail($detail, value);
      }, this));

      this.data = data;
    }
617454
function createGeo() {
    $cnt = count( $this->geo );
    if( 0 >= $cnt )
      return;
    $attributes = $this->_createParams( $this->geo['params'] );
    $content    = null;
    $content   .= number_format( (float) $this->geo['value']['latitude'], 6, '.', '');
    $content   .= ';';
    $content   .= number_format( (float) $this->geo['value']['longitude'], 6, '.', '');
    return $this->_createElement( 'GEO', $attributes, $content );
  }
1210529
public function fromArray(array $data = [])
    {
        if (isset($data['providerName'])) {
            $this->providerName = $data['providerName'];
        }
        if (isset($data['query'])) {
            $this->query = $data['query'];
        }
        if (isset($data['exception'])) {
            $this->exception = $data['exception'];
        }

        //GeoCoder Address::createFromArray expects longitude/latitude keys
        $data['address']['longitude'] = $data['address']['coordinates']['longitude'] ?? null;
        $data['address']['latitude'] = $data['address']['coordinates']['latitude'] ?? null;

        // Shortcut to create the address and set it in this class
        $this->setAddress(Address::createFromArray($data['address']));
    }
660365
private function geocodeQueryString() {
      $queryString = array();

      // One of the following is required.
      $address = $this->getAddress();
      $latitudeLongitude = $this->getLatitudeLongitude();

      // If both are set for some reason, favor address to geocode.
      if ($address) {
        $queryString['address'] = $address;
      }
      elseif ($latitudeLongitude) {
        $queryString['latlng'] = $latitudeLongitude;
      }

      // Optional parameters.
      $queryString['bounds'] = $this->getBounds();
      $queryString['region'] = $this->getRegion();
      $queryString['language'] = $this->getLanguage();
      $queryString['result_type'] = $this->getResultTypeFormatted();
      $queryString['location_type'] = $this->getLocationTypeFormatted();

      // Required.
      $queryString['sensor'] = $this->getSensor();

      // Remove any unset parameters.
      $queryString = array_filter($queryString);

      // The signature is added later using the path + query string.
      if ($this->isBusinessClient()) {
        $queryString['client'] = $this->getClientId();
      }
      elseif ($this->getApiKey()) {
        $queryString['key'] = $this->getApiKey();
      }

      // Convert array to proper query string.
      return http_build_query($queryString);
    }
801322
protected function mapTheliaAddress($address, $locale = null)
    {
        $country = $address->getCountry();
        if (null === $locale) {
            $locale = Lang::getDefaultLanguage()->getLocale();
        }
        $customerTitle = $address->getCustomerTitle()
            ->setLocale($this->denormalizeLocale($locale))
            ->getShort()
        ;

        $addressModel = new Address();
        $addressModel = $addressModel
            ->withCountryCode($country->getIsoalpha2())
            ->withAddressLine1($address->getAddress1())
            ->withAddressLine2($address->getAddress2())
            ->withPostalCode($address->getZipcode())
            ->withLocality($address->getCity())
            ->withOrganization($address->getCompany())
            ->withRecipient(
                sprintf(
                    '%s %s %s',
                    $customerTitle,
                    $address->getLastname(),
                    $address->getFirstname()
                )
            )
        ;


        if ($country->getHasStates() && \intval($address->getStateId()) !== 0) {
            $addressModel = $addressModel->withAdministrativeArea(
                sprintf(
                    '%s-%s',
                    $country->getIsoalpha2(),
                    $address->getState()->getIsocode()
                )
            );
        }

        return $addressModel;
    }
579149
public GeocodingResult toGeocodingResult(
            final GeoServiceGeocodingResult gsResult) {
        if (gsResult == null) {
            return null;
        }
        final GeocodingResult result = new GeocodingResult();
        final AddressComponent[] addressComponents =
                gsResult.getAddressComponents();
        if (addressComponents == null) {
            result.addressComponents = null;
        } else {
            result.addressComponents =
                    new AddressComponent[addressComponents.length];
            for (int i = 0; i < addressComponents.length; i++) {
                result.addressComponents[i] = copy(addressComponents[i]);
            }
        }
        result.formattedAddress = gsResult.getFormattedAddress();
        result.geometry = toGeometry(gsResult.getGeometry());
        result.partialMatch = gsResult.isPartialMatch();
        result.placeId = gsResult.getPlaceId();
        // This is safe because the gs object returns a copy of its array.
        result.postcodeLocalities = gsResult.getPostcodeLocalities();
        // This is safe because the gs object returns a copy of its array.
        result.types = gsResult.getTypes();
        return result;
    }
29289
def address_to_coords(self, address):
        """"""

        base_coords = self.BASE_COORDS[self.region]
        get_cord = self.COORD_SERVERS[self.region]
        url_options = {
            "q": address,
            "lang": "eng",
            "origin": "livemap",
            "lat": base_coords["lat"],
            "lon": base_coords["lon"]
        }

        response = requests.get(self.WAZE_URL + get_cord, params=url_options, headers=self.HEADERS)
        for response_json in response.json():
            if response_json.get('city'):
                lat = response_json['location']['lat']
                lon = response_json['location']['lon']
                bounds = response_json['bounds']  # sometimes the coords don't match up
                if bounds is not None:
                    bounds['top'], bounds['bottom'] = max(bounds['top'], bounds['bottom']), min(bounds['top'], bounds['bottom'])
                    bounds['left'], bounds['right'] = min(bounds['left'], bounds['right']), max(bounds['left'], bounds['right'])
                else:
                    bounds = {}
                return {"lat": lat, "lon": lon, "bounds": bounds}
        raise WRCError("Cannot get coords for %s" % address)
1098544
public final Object fromAddress(long address) {
		Object[] array = new Object[] { null };
		long baseOffset = THE_UNSAFE.arrayBaseOffset(Object[].class);
		THE_UNSAFE.putLong(array, baseOffset, address);
		return array[0];
	}
61522
public function getAddressInfo()
    {
        $address = new Address();

        $address->setAddress($this->getAddress());
        $address->setPostalCode($this->getPostalCode());
        $address->setCity($this->getCity());
        if(!is_null($this->getState()))$address->setState($this->getState());
        $address->setCountry($this->getCountry());

        return $address;
    }
435835
public function paymentAddressStepAction()
    {
        $request = $this->getCurrentRequest();
        $basket = $this->get('sonata.basket');

        if (0 === $basket->countBasketElements()) {
            return new RedirectResponse($this->generateUrl('sonata_basket_index'));
        }

        $customer = $basket->getCustomer();

        if (!$customer) {
            throw new NotFoundHttpException('customer not found');
        }

        $addresses = $customer->getAddressesByType(AddressInterface::TYPE_BILLING);

        // Show address creation / selection form
        $form = $this->createForm(AddressType::class, null, ['addresses' => $addresses->toArray()]);
        $template = 'SonataBasketBundle:Basket:payment_address_step.html.twig';

        if ('POST' === $request->getMethod()) {
            $form->handleRequest($request);

            if ($form->isValid()) {
                if ($form->has('useSelected') && $form->get('useSelected')->isClicked()) {
                    $address = $form->get('addresses')->getData();
                } else {
                    $address = $form->getData();
                    $address->setType(AddressInterface::TYPE_BILLING);

                    $customer->addAddress($address);

                    $this->get('sonata.customer.manager')->save($customer);

                    $this->get('session')->getFlashBag()->add('sonata_customer_success', 'address_add_success');
                }

                $basket->setCustomer($customer);
                $basket->setBillingAddress($address);
                // save the basket
                $this->get('sonata.basket.factory')->save($basket);

                return new RedirectResponse($this->generateUrl('sonata_basket_payment'));
            }
        }

        // Set URL to be redirected to once edited address
        $this->get('session')->set('sonata_address_redirect', $this->generateUrl('sonata_basket_payment_address'));

        $this->get('sonata.seo.page')->setTitle($this->get('translator')->trans('basket_payment_title', [], 'SonataBasketBundle'));

        return $this->render($template, [
            'form' => $form->createView(),
            'addresses' => $addresses,
        ]);
    }
269610
public function createSentinel()
    {
        $persistence = $this->createPersistence();
        $users       = $this->createUsers();
        $roles       = $this->createRoles();
        $activations = $this->createActivations();
        $dispatcher  = $this->getEventDispatcher();

        $sentinel = new Sentinel(
            $persistence,
            $users,
            $roles,
            $activations,
            $dispatcher
        );

        $throttle = $this->createThrottling();

        $ipAddress = $this->getIpAddress();

        $checkpoints = $this->createCheckpoints($activations, $throttle, $ipAddress);

        foreach ($checkpoints as $key => $checkpoint) {
            $sentinel->addCheckpoint($key, $checkpoint);
        }

        $reminders = $this->createReminders($users);

        $sentinel->setActivationRepository($activations);

        $sentinel->setReminderRepository($reminders);

        $sentinel->setThrottleRepository($throttle);

        return $sentinel;
    }
201421
protected function createGeocoder()
    {
        if ($this->apiKey === null) {
            throw new Exception('API key must be set before geocoding.');
        }

        if ($this->geocoder === null) {
            $this->geocoder = new GoogleMaps(
                new CurlHttpAdapter,
                $this->lang,
                null,
                true,
                $this->apiKey
            );
        }

        return $this->geocoder;
    }
808277
public static function getCoordinates($address)
    {
        $config = Kwf_Registry::get('config');
        $q = $address;
        $q = str_replace(array('ä','ö','ü','Ä','Ö','Ü','ß'), array('ae','oe','ue','Ae','Oe','Ue','ss'), $q);
        $getParams = array(
            'address' => $q,
            'sensor' => 'false',
            'key' => $config->googleServerToServerApiKey
        );

        $httpClientConfig = array(
            'timeout' => 20,
            'persistent' => false
        );

        if ($config->http && $config->http->proxy && $config->http->proxy->host && $config->http->proxy->port) {
            $httpClientConfig['adapter'] = 'Zend_Http_Client_Adapter_Proxy';
            $httpClientConfig['proxy_host'] = $config->http->proxy->host;
            $httpClientConfig['proxy_port'] = $config->http->proxy->port;
        }

        $client = new Zend_Http_Client("https://maps.googleapis.com/maps/api/geocode/json", $httpClientConfig);
        $client->setMethod(Zend_Http_Client::GET);
        $client->setParameterGet($getParams);
        $body = utf8_encode($client->request()->getBody());

        try {
            $result = Zend_Json::decode($body);
        } catch (Zend_Json_Exception $e) {
            $e = new Kwf_Exception_Other($e);
            $e->logOrThrow();
        }

        if (isset($result['results'][0]['geometry']['location']['lat'])
            && isset($result['results'][0]['geometry']['location']['lng'])
        ) {
            return array(
                'lat' => $result['results'][0]['geometry']['location']['lat'],
                'lng' => $result['results'][0]['geometry']['location']['lng']
            );
        }
        return null;
    }
514137
public function buildAddressOptions() {
    $address_formatter = new ACMAddressFormatter();
    $user = $this->getCurrentCommerceUser();
    $addresses = $user->getAddresses();

    // Stored addresses.
    foreach ($addresses as $address) {
      $option_id = $address['address_id'];
      $options[$option_id] = [
        'id' => $option_id,
        'label' => $address_formatter->render((object) $address),
      ];
    }

    // New address.
    $option_id = 'new_address';
    $options[$option_id] = [
      'id' => $option_id,
      'label' => $this->t('New address'),
    ];

    return $options;
  }
630635
public function getCoordinates($address)
    {
        if (! empty($this->country)) {
            $address = trim($address) . ' ' . $this->country;
        }

        // Sanitize the address:
        $search_code = urlencode($address);

        // Retrieve the latitude and longitude
        $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $search_code . '&sensor=false';

        // If Google Maps API fails, catch it and throw a better error
        $json = $this->api->fetch($url);

        if(!empty($json->results)) {
            $lat = $json->results[0]->geometry->location->lat;
            $lng = $json->results[0]->geometry->location->lng;

            return [
                'latitude'  => $lat,
                'longitude' => $lng
            ];
        }

        // We must have nothing if we've got here
        return [];
    }
704013
protected function wizardAddAddress()
    {
        $types = $this->address->getTypes();
        $this->validateMenu('type', $this->text('Address type'), 'address', array_combine($types, $types), 'shipping');

        $this->validatePrompt('user_id', $this->text('User ID'), 'address');
        $this->validatePrompt('country', $this->text('Country code'), 'address');
        $this->validatePrompt('state_id', $this->text('Country state ID'), 'address');
        $this->validatePrompt('city_id', $this->text('City ID'), 'address');
        $this->validatePrompt('address_1', $this->text('Address'), 'address');
        $this->validatePrompt('address_2', $this->text('Additional address'), 'address');
        $this->validatePrompt('phone', $this->text('Phone'), 'address');
        $this->validatePrompt('postcode', $this->text('Post code/ZIP'), 'address');
        $this->validatePrompt('company', $this->text('Company'), 'address');
        $this->validatePrompt('fax', $this->text('Fax'), 'address');
        $this->validatePrompt('first_name', $this->text('First name'), 'address');
        $this->validatePrompt('middle_name', $this->text('Middle name'), 'address');
        $this->validatePrompt('last_name', $this->text('Last name'), 'address');
        $this->validatePrompt('data', $this->text('Data'), 'address');

        $this->setSubmittedJson('data');
        $this->validateComponent('address');
        $this->addAddress();
    }