Answer the question
In order to leave comments, you need to log in
ZF2 Module (or whatever) for working with Yandex|Google Map Api?
PHP - migrating from one database to another. In the new database, there is a new field in the table, with the geolocation coordinates of the object (address). When transferring, you need to somehow get the coordinates of the area using Yandex or Google by the name of the address (or the nearest river / lake). (well, at least I think so)
How is it implemented differently (if suddenly I'm not reasoning correctly)?
Is there a module for communicating with the API via php (project on ZF2)
Answer the question
In order to leave comments, you need to log in
function makeGoogleApiRequest($params)
{
$apiUrl = "https://maps.googleapis.com/maps/api/geocode/json";
$context = stream_context_create(['http'=>['timeout'=>5]]);
// Make request
$response = json_decode(file_get_contents($apiUrl . "?" . http_build_query($params), false, $context));
// Check response
if (
json_last_error() ||
!isset($response->status) ||
$response->status !== "OK" ||
!isset($response->results[0]->place_id) ||
!isset($response->results[0]->formatted_address) ||
!isset($response->results[0]->address_components) ||
!isset($response->results[0]->geometry->location->lat) ||
!isset($response->results[0]->geometry->location->lng)
) {
throw new \UnexpectedValueException ("Google Api Request Failed");
}
return $response;
}
/* Пример использования */
$place = makeGoogleApiRequest([
'address' => "Москва, Лаврушинский пер, 10",
'language' => "ru"
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question