Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/Common/Query/GeocodeQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,24 @@ public function getLimit()
}

/**
* Return arbitrary data for this query.
* @param string $name
* @param null $default
*
* @return mixed
*/
public function getData($name, $default = null)
{
if (!array_key_exists($name, $this->data)) {
return $default;
}

return $this->data[$name];
}

/**
* @return array
*/
public function getData()
public function getAllData()
{
return $this->data;
}
Expand Down
17 changes: 16 additions & 1 deletion src/Common/Query/ReverseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,25 @@ public function getLocale()
return $this->locale;
}

/**
* @param string $name
* @param null $default
*
* @return mixed
*/
public function getData($name, $default = null)
{
if (!array_key_exists($name, $this->data)) {
return $default;
}

return $this->data[$name];
}

/**
* @return array
*/
public function getData()
public function getAllData()
{
return $this->data;
}
Expand Down
12 changes: 2 additions & 10 deletions src/Provider/Nominatim/Nominatim.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ public function geocodeQuery(GeocodeQuery $query)
$url = sprintf($this->getGeocodeEndpointUrl(), urlencode($address), $query->getLimit());
$content = $this->executeQuery($url, $query->getLocale());

if (empty($content)) {
throw InvalidServerResponse::create($url);
}

$doc = new \DOMDocument();
if (!@$doc->loadXML($content) || null === $doc->getElementsByTagName('searchresults')->item(0)) {
throw InvalidServerResponse::create($url);
Expand Down Expand Up @@ -102,13 +98,9 @@ public function reverseQuery(ReverseQuery $query)
$coordinates = $query->getCoordinates();
$longitude = $coordinates->getLongitude();
$latitude = $coordinates->getLatitude();
$url = sprintf($this->getReverseEndpointUrl(), $latitude, $longitude);
$url = sprintf($this->getReverseEndpointUrl(), $latitude, $longitude, $query->getData('zoom', 18));
$content = $this->executeQuery($url, $query->getLocale());

if (empty($content)) {
return new AddressCollection([]);
}

$doc = new \DOMDocument();
if (!@$doc->loadXML($content) || $doc->getElementsByTagName('error')->length > 0) {
return new AddressCollection([]);
Expand Down Expand Up @@ -193,7 +185,7 @@ private function getGeocodeEndpointUrl()

private function getReverseEndpointUrl()
{
return $this->rootUrl.'/reverse?format=xml&lat=%F&lon=%F&addressdetails=1&zoom=18';
return $this->rootUrl.'/reverse?format=xml&lat=%F&lon=%F&addressdetails=1&zoom=%d';
}

private function getNodeValue(\DOMNodeList $element)
Expand Down