simplemap icon indicating copy to clipboard operation
simplemap copied to clipboard

Normalize Location error for partial postcode search

Open iamtompickering opened this issue 3 years ago • 1 comments

I seem to be hitting the following error when I try and search with specific postcodes both partial and full e.g. 'WN4' or 'WN4 5DH'. Other postcode variations seem to work absolutely fine. but there seems to be some issue with ones that include 'WN'?!

Is there any reason why this would be happening? Screenshot of error below.

CleanShot 2023-01-17 at 09 54 07

iamtompickering avatar Jan 17 '23 09:01 iamtompickering

I also ran into this issue. It seems to be thrown when $location is a string, but is an invalid GeoService location.

In this case, line 677 $location = self::latLngFromAddress($location, $country); returns null.

I was able to resolve this by adding a null check to the function: public static function normalizeLocation (mixed $location, string $country = null): array

public static function normalizeLocation (mixed $location, string $country = null): array
{
	if (is_string($location))
		$location = self::latLngFromAddress($location, $country);
	else if ($location instanceof Map)
		$location = ['lat' => $location->lat, 'lng' => $location->lng];
	else if (!is_array($location) || !isset($location['lat'], $location['lng']))
		$location = [];

        // added null check for $location
	if (!$location) {
		$location = [];
	}

	return $location;
}

Decyphr avatar Jun 23 '23 16:06 Decyphr