File

libs/upp-base/src/modules/geocode.ts

Description

Provides geocoding and geolocation services for interacting with Google Maps API to retrieve address, timezone, and positional data.

Index

Properties
Methods
Accessors

Constructor

constructor(androidPermissions: AndroidPermissions, geolocation: Geolocation, http: httpService, lang: languageService, modalCtrl: ModalController, alertCtrl: alertService, toast: toastService, platform: platformService)

Initializes the service and requests Android permissions if applicable.

Parameters :
Name Type Optional
androidPermissions AndroidPermissions No
geolocation Geolocation No
http httpService No
lang languageService No
modalCtrl ModalController No
alertCtrl alertService No
toast toastService No
platform platformService No

Methods

DistanceTo
DistanceTo(coordinates: Coordinates)

Calculates the distance in meters between the current position and specified coordinates.

Parameters :
Name Type Optional Description
coordinates Coordinates No
  • Target coordinates.
Returns : number

Distance in meters.

GetCurrentPosition
GetCurrentPosition(resolve: GeocodePositionCallback, reject: GeocodePositionErrorCallback)

Retrieves the current geolocation position.

Parameters :
Name Type Optional Description
resolve GeocodePositionCallback No
  • Callback function executed on successful location retrieval.
reject GeocodePositionErrorCallback No
  • Callback function executed on failed location retrieval.
Returns : void
LoadGoogleMaps
LoadGoogleMaps(loaded: Subject)
Parameters :
Name Type Optional
loaded Subject<boolean> No
Returns : Promise<void>
Async NearBy
NearBy(center: Coordinates | null, radius: number)

Enables or disables a proximity-based restriction. Starts watching the position if required and checks proximity.

Parameters :
Name Type Optional Default value Description
center Coordinates | null No
  • The center coordinates or null to disable the restriction.
radius number No 250
  • Radius in meters (default is 250).
Returns : Promise<boolean>

A promise resolving to true if within radius or restriction is disabled, false otherwise.

RequestAddress
RequestAddress(lat: number, lng: number)

Requests address data from the Google Geocoding API based on latitude and longitude. Caches responses to reduce repeated network requests.

Parameters :
Name Type Optional Description
lat number No
  • Latitude of the requested location.
lng number No
  • Longitude of the requested location.
Returns : Promise<any>

A promise resolving to address data or null if an error occurs.

RequestTimezne
RequestTimezne(lat: number, lng: number)

Requests timezone information for a specific location using the Google Timezone API.

Parameters :
Name Type Optional Description
lat number No
  • Latitude of the requested location.
lng number No
  • Longitude of the requested location.
Returns : Promise<string>

A promise resolving to the timezone ID or 'UTC' if an error occurs.

ResolveAddress
ResolveAddress(address: string)

Resolves an address from a string query using the Google Geocoding API. Caches responses to optimize repeated lookups.

Parameters :
Name Type Optional Description
address string No
  • The address query string.

A promise resolving to parsed address data or false if an error occurs.

StaticUrl
StaticUrl(lat: number, lng: number, width: number, height: number, zoom: number)

Generates a static map URL for a specific latitude and longitude.

Parameters :
Name Type Optional Default value Description
lat number No
  • Latitude of the center point.
lng number No
  • Longitude of the center point.
width number No
  • Width of the generated map image.
height number No
  • Height of the generated map image.
zoom number No 15
  • Zoom level (default is 15).
Returns : string

The constructed URL for the static map image.

WaitForNear
WaitForNear(center: Coordinates, radius: number)

Waits until the current position is within a specified radius of the center coordinates. Shows a modal if the user is outside the radius, and waits until they are nearby.

Parameters :
Name Type Optional Default value Description
center Coordinates No
  • The center coordinates.
radius number No 250
  • Radius in meters (default is 250).
Returns : Promise<boolean>

A promise resolving to true if within radius, false otherwise.

Properties

Public GMAP_API_LOADED
Default value : false
Public OnPositionChanged
Default value : this._positionChanged.asObservable()

Accessors

CanGeolocate
getCanGeolocate()

Checks if geolocation services are available on the platform.

CurrentPosition
getCurrentPosition()

Returns the currently watched position

Returns : WatchPosition

results matching ""

    No results matching ""