A simple module to handle geolocation in browser
- Properties
- Methods
- checkAvailability
- findCurrentPosition
- watchPosition
- stopWatchingPosition
- injectScript
- geocodeLatLng
- initMap
- setAddressIntoInput
- Basic example
- isAvailable : boolean
- watcherId : number;
- version : string;
- position : Position
- geocoder : Geocoder
- map : google.maps.Map
- infowindow : google.maps.InfoWindow
- latlng : google.maps.LatLng
Checks if geolocation is available in current browser
checkAvailability(): boolean;
Retrieve current coordonates of the user
findCurrentPosition(callbackSuccess: ((coordonates: LatLng) => void), callbackError?: ((error: PositionError) => void)): void;
Retrieve current coordonates of the user periodically
watchPosition(callbackSuccess: ((lat: number, lng: number) => void), callbackError?: ((error: PositionError) => void), enableHighAccuracy?: boolean, maximumAge?: number, timeout?: number): void;
Stop periodical retrieving of coordonates previously called with watchPosition method
stopWatchingPosition(): void;
Inject javascript script tag for Google Map API
injectScript(callbackSuccess: () => void, callbackError?: (error: any) => void): void;
Retrieve human readable address from coordonates
geocodeLatLng(coordonates: LatLng, callbackSUccess: (adress: string) => void): void;
Initialize a Google Map into the html element with id htmlElementIdWithoutHashtag. The map will be centered using the options parameter as following {zoom: number, center: LatLng}, LatLng being the google map specific object for coordinates
initMap(htmlElementIdWithoutHashtag: string, options: MapOptions): void;
Combine all methods to ask for geolocation authorization, retieve coordinates, transform coordinates into human readable adress, display address into the input designated by the inputReceiverSelector or by default into the input selectable with #addressReceiver, and potentially init a map centered on found coordinates with address displayed into an infoWindow
setAddressIntoInput(inputReceiverSelector?: string, apiKey?: string, version?: string, initMap?: boolean, htmlElementIdWithoutHashtag?: string): void;
Retrieve user adress and place it into a text input
var a_geolocation = require("a_geolocation");
let aGeolocation = new a_geolocation.AGeolocation();
aGeolocation.setAddressIntoInput("#addressInputReceiver", "ReplaceMeWithYourApiKey");