An open source location picker plugin using Google Maps v3 that works with all JavaScript flavors!
npm install location-pickerlocation-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!
* Google Maps v3
```
npm install location-picker --save
From node_modules:
`html`
From CDN:
`html`
`typescript`
import LocationPicker from "location-picker";
`javascript`
var locationPicker = require("location-picker")
`html`
#map {
width: 100%;
height: 480px;
}
#### Plain JavaScript:
`javascript`
var locationPicker = new 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:
`typescript`
let lp = new 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
});
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 if lat and lng 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
Returns an object that contains the lat and lng of the currently selected position.
A reference to the element the plugin was initialized on.
A reference to the Google Map object
html
Example
src="https://maps.googleapis.com/maps/api/js?key={{ENTER YOUR KEY}}">
On idle position:
On click position:
`$3
* Import Google maps:
One example could be adding in
index.html:
`html
`* Add map element and button in HTML:
`html
`* Add this CSS:
`css
#map {
width: 100%;
height: 480px;
}
`* Component:
`typescript
import {Component} from '@angular/core';
import LocationPicker from "location-picker";@Component({
selector: 'page-location',
templateUrl: 'location.html'
})
export class LocationPage implements OnInit {
lp: LocationPicker;
ngOnInit(){
this.lp = new LocationPicker('map');
}
setLocation() {
console.log(this.lp.getMarkerPosition());
}
}
``