🗺🎯 location-picker
Efficiently allow your users to pick a location!
location-picker allows you to quickly render Google Maps with an overlaying marker providing an easy and quick plug-and-play location picker. It uses Google Maps v3 and it works with all JavaScript flavors!
Requirements
- Google Maps v3
Installation
npm install location-picker --save
Import libraries using HTML:
From node_modules
:
From CDN:
Import using Typescript or Angular
;
Import using CommonJS / Node:
var locationPicker =
Usage
Add element in HTML with a unique id:
#map { width: 100%; height: 480px;}
Initialize the locationPicker plugin:
Plain JavaScript:
var locationPicker = 'map' setCurrentPosition: true // You can omit this, defaults to true zoom: 15 // You can set any google map options here, zoom defaults to 15;
Angular:
;
Methods
locationPicker(elementId, pluginOptions, mapOptions)
Returns a reference to the locationPicker object
element
: string
| HTMLElement
The ID of the HTML element you want to initialize the plugin on or a direct reference to the HTMLElement.
pluginOptions
:
Options specific for this plugin
lat
: latitude of initial needed positionlng
: longitude of initial needed positionsetCurrentPosition
: specifies if you want the plugin to automatically try and detect and set the marker to the the current user's location. It has no effect iflat
andlng
are supplied. (defaults to true)
mapOptions
:
You can set any specific google maps option here.
For a list of all the available options please visit:
https://developers.google.com/maps/documentation/javascript/reference#MapOptions
locationPicker.getMarkerPosition()
Returns an object that contains the lat and lng of the currently selected position.
Properties
locationPicker.element
A reference to the element the plugin was initialized on.
locationPicker.map
A reference to the Google Map object
Examples
HTML Full Example
Example Confirm PositionOn idle position: On click position:
Angular Example
- Import Google maps:
One example could be adding in index.html
:
- Add map element and button in HTML:
Submit Location
- Add this CSS:
- Component:
;;