Skip to content

Commit 0b132a6

Browse files
author
Andrea Barbasso
committed
[UXP-206] try to use given coordinates if nominatim api fails
1 parent a50dece commit 0b132a6

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/app/core/services/location.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export enum LocationErrorCodes {
2525
API_ERROR = 'api-error',
2626
}
2727

28-
const IS_DD_COORDINATE_PAIR_REGEXP = /^\d+\.?\d*,\d+\.?\d*$/;
28+
const IS_DD_COORDINATE_PAIR_REGEXP = /^\d+\.?\d*,\s?\d+\.?\d*$/;
2929
const IS_SG_COORDINATE_PAIR_REGEXP = /^[NS] *\d+° *\d+['] *\d+(?:"||\.\d+),? *[EW] *\d+° *\d+['] *\d+(?:"||\.\d+)|\d+° *\d+['] *\d+(?:"||\.\d+) *[NS],? *\d+° *\d+['] *\d+(?:"||\.\d+) *[EW]$/;
3030

3131
const NOMINATIM_RESPONSE_FORMAT = 'jsonv2';
@@ -176,8 +176,8 @@ export class LocationService {
176176
public isValidCoordinateString(coordinateString: string): boolean {
177177
if (this.isDecimalCoordinateString(coordinateString)) {
178178
const coordinateArray = coordinateString.split(',');
179-
const latitude = parseFloat(coordinateArray[0]);
180-
const longitude = parseFloat(coordinateArray[1]);
179+
const latitude = parseFloat(coordinateArray[0].trim());
180+
const longitude = parseFloat(coordinateArray[1].trim());
181181
return !isNaN(latitude) && !isNaN(longitude) && this.isValidDecimalCoordinatePair(latitude, longitude);
182182
} else {
183183
return false;

src/app/shared/open-street-map/open-street-map.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ export class OpenStreetMapComponent implements OnInit {
170170
},
171171
error: (err) => {
172172
this.invalidLocationErrorCode.next(err.message); // either INVALID_COORDINATES or API_ERROR
173+
// show the map centered on provided coordinates despite the possibility to retrieve a description for the place
174+
const coordinates = this.locationService.parseCoordinates(position);
175+
const place: LocationPlace = {
176+
coordinates: coordinates,
177+
};
178+
this.place.next(place);
173179
if (err.message === LocationErrorCodes.API_ERROR) {
174180
console.error(err.message);
175181
} else {
@@ -189,6 +195,12 @@ export class OpenStreetMapComponent implements OnInit {
189195
},
190196
error: (err) => {
191197
this.invalidLocationErrorCode.next(err.message); // either LOCATION_NOT_FOUND or API_ERROR
198+
// show the map centered on provided coordinates despite the possibility to retrieve a description for the place
199+
const coordinates = this.locationService.parseCoordinates(position);
200+
const place: LocationPlace = {
201+
coordinates: coordinates,
202+
};
203+
this.place.next(place);
192204
if (err.message === LocationErrorCodes.API_ERROR) {
193205
console.error(err.message);
194206
} else {

0 commit comments

Comments
 (0)