Map widget to get lat and lng using Google Maps.
First load Google Maps API using your own API KEY, then just load jQuery and jQuery.MapMarker.
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
<script src="jquery.min.js"></script>
<script src="jquery.mapmarker.js"></script>
Just specify latField
and lngField
properties, wich are the selectors of the input fields
where you want to store the lat and long values when the user select a location in the map.
$('#map-canvas').mapMarker({
latField: '#latInputField',
lngField: '#lngInputField'
});
Now, when the user select a location in the map, your input fields will be updated with the lat and long values, is up to you store this values as you wish.
Default latitude value when latField
is not present or the field value is empty.
Default: 0
Default longitude value when lngField
is not present or the field is empty.
Default: 0
CSS selector of the field where to store/read latitude value.
Default: null
CSS selector of the field where to store/read longitude value.
Default: null
This function is called when a new location in the map is selected or the marker is dragged to a new location.
Arguments:
-
location {google.maps.LatLng}
onChange: function (location) { console.log('The new location is ' + location.lat() + ', ' + location.lng()); }
This function is called when a search starts.
onSearchStart: function ()
{
// Code to show a spinner or something...
}
This function is called when the search finish and after the results are printed in the view.
Arguments:
-
status {Number}
onSearchEnd: function (status) { if (status == google.maps.GeocoderStatus.ZERO_RESULTS) { alert('No address found!'); }
// Do something with other status codes...
}
Options to pass directly to goole.map.Map(...)
, see Google Maps API Reference for a complete list of options.
Default:
{
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 12
}
Options to pass directly to goole.map.Marker(...)
, see Google Maps API Reference for a complete list of options.
Default:
{
draggable: true
}
CSS selector of the view (div) where to show the search results.
Default: null
Template for each result, the string :address
will be replaced with the result address.
Default: '<a href="#">:address</a>'
Default zoom to apply when a search result is clicked.
Place the marker into a new location in the map.
This method triggers options.onChange()
event.
Arguments:
- location {google.maps.LatLng}
Search address using Google's Geocoder service and display the results within the options.resultsView
.
This method triggers options.onSearchStart()
and options.onSearchEnd()
events.
The map is disabled when the search is running.
Arguments:
- address {String}
Disable/enable the map.
Arguments:
- disable {Boolean}
Get the current google.maps.Map
object.