2 my $conf = new FS::Conf;
3 my $apikey = $conf->config('google_maps_api_key');
7 # Currently requires two fields named 'latitude' and 'longitude'.
8 # Those should be in the edit form. This widget should NOT be in the
9 # edit form (or it will submit a bunch of spurious fields, plus pressing
10 # "enter" in the search box will submit the form).
13 <script src="https://maps.googleapis.com/maps/api/js?v=3&libraries=places&key=<% $apikey %>"></script>
14 <script src="<% $fsurl %>elements/jquery-gmaps-latlon-picker.js"></script>
16 .gllpLatlonPicker, .gllpMap { width: 600px; height: 600px }
17 #search_location { width: 300px }
19 <fieldset id="latlonpicker" class="gllpLatlonPicker" style="float: right">
20 <input type="text" id="search_location">
21 <input type="hidden" class="gllpLatitude" id="map_lat">
22 <input type="hidden" class="gllpLongitude" id="map_lon">
23 <input type="hidden" class="gllpElevation" id="map_alt">
24 <input type="hidden" class="gllpZoom" id="map_zoom" value="12">
25 <div class="gllpMap"></div>
32 var container = $('#latlonpicker');
33 var map = gMapsLatLonPickerState['latlonpicker'].vars.map;
35 var lat = $('#latitude');
36 var lon = $('#longitude');
37 var alt = $('#altitude');
38 $('#map_lat').val(lat.val());
39 $('#map_lon').val(lon.val());
40 $('#map_alt').val(alt.val());
41 $(document).trigger('gllp_update_fields');
43 $(document).on('location_changed', function(ev, obj) {
44 lat.val($('#map_lat').val());
45 lon.val($('#map_lon').val());
48 // requires the Elevation API to be enabled
49 $(document).on('elevation_changed', function(ev, obj) {
50 alt.val($('#map_alt').val());
53 // bypass gllp's search mechanism, use the cooler Places search
54 var searchbox_input = $('#search_location')[0];
55 var searchbox = new google.maps.places.SearchBox(searchbox_input);
56 map.controls[google.maps.ControlPosition.TOP_RIGHT].push(searchbox_input);
58 map.addListener('bounds_changed', function() {
59 searchbox.setBounds(map.getBounds());
62 searchbox.addListener('places_changed', function() {
63 var places = searchbox.getPlaces();
65 $('#map_lat').val( places[0].geometry.location.lat() );
66 $('#map_lon').val( places[0].geometry.location.lng() );
67 $('#map_zoom').val(12);
68 $(document).trigger('gllp_update_fields');