burgerking_module
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    Geolocation module

    A simple module to handle geolocation in browser

    Summary

    • Properties
    • Methods
      • checkAvailability
      • findCurrentPosition
      • watchPosition
      • stopWatchingPosition
      • injectScript
      • geocodeLatLng
      • initMap
      • setAddressIntoInput
    • Basic example

    Properties

    • isAvailable : boolean
    • watcherId : number;
    • version : string;
    • position : Position
    • geocoder : Geocoder
    • map : google.maps.Map
    • infowindow : google.maps.InfoWindow
    • latlng : google.maps.LatLng

    Methods

    checkAvailability

    Checks if geolocation is available in current browser

    checkAvailability(): boolean;
    findCurrentPosition

    Retrieve current coordonates of the user

    findCurrentPosition(callbackSuccess: ((coordonates: LatLng) => void), callbackError?: ((error: PositionError) => void)): void;
    watchPosition

    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;
    stopWatchingPosition

    Stop periodical retrieving of coordonates previously called with watchPosition method

    stopWatchingPosition(): void;
    injectScript

    Inject javascript script tag for Google Map API

    injectScript(callbackSuccess: () => void, callbackError?: (error: any) => void): void;
    geocodeLatLng

    Retrieve human readable address from coordonates

    geocodeLatLng(coordonates: LatLng, callbackSUccess: (adress: string) => void): void;
    initMap

    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;
    setAddressIntoInput

    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;

    Basic example:

    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");

    Install

    npm i burgerking_module

    DownloadsWeekly Downloads

    6

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • jeansaigne