LocPicker is a JS widget that creates a minimal, domain agnostic Location Picker in a given <div>
.
<script src="https://mercury.ourtownamerica.com/LocPicker/widget.js?key={my API key}"></script>
<div id='otmap'></div>
<script> var otmap = new LocPicker({id: 'otmap'}); </script>
var lp = new LocPicker(options)
Constructor creates the new LocPicker object.
Parameterslp.load(cb)
Register a function to be called once the widget has loaded, or if it is alreadye loaded, immediately.
ParametersThis method returns the LocPicker instance
lp.onFinished(cb)
Register a function to be called when the user presses thee finished button.
ParametersThis method returns the LocPicker instance
lp.getLocations()
Get an array of location objects
ReturnsAn array of location objects. Each object contains the following properties:
lp.getLocations()
Get an array of location objects
ReturnsAn array of location objects. Each object contains the following properties:
lp.collapsePanel()
Collapse the apnel
ReturnsThis method returns the LocPicker instance
lp.showPanel()
Set the text of the button
ReturnsThis method returns the LocPicker instance
<!DOCTYPE html>
<html>
<head>
<title>LocPicker Widget Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body{
margin: 1em 5em;
}
</style>
</head>
<body>
<center>
<h1>LocPicker Widget Example</h1>
<a href="https://mercury.ourtownamerica.com/LocPicker/docs.html">Click here for documentation</a>
</center>
<div id="output"></div>
<div id="results"></div>
<script src="https://mercury.ourtownamerica.com/LocPicker/widget.js?key={My key}"></script>
<script>
var lp = new LocPicker({id: "output"}).onFinished(function(){
var locations = lp.getLocations();
var htmlbuffer = [];
htmlbuffer.push("<h1>Chosen Locations</h1><hr>");
if(!locations.length){
htmlbuffer.push("No locations chosen.<hr>");
}else{
for(var i=0; i<locations.length; i++){
if(locations.corrupt) continue;
htmlbuffer.push("<b>Inputted location: </b>"+locations[i].orig+"<br>");
htmlbuffer.push("<b>Formatted location: </b>"+locations[i].formatted+"<br>");
htmlbuffer.push("<b>Zip code: </b>"+locations[i].zipOrRoute+"<br>");
htmlbuffer.push("<b>Geolocation: </b>"+locations[i].lat+", "+locations[i].lng+"<br>");
htmlbuffer.push("<hr>");
}
}
document.getElementById("results").innerHTML = htmlbuffer.join('');
});
</script>
</body>
</html>