Function Reference: geodir_location_autofill_address
Summary
Adds js to autofill the address.
Global Values
- $post
- (object) (required) The current post object.
- Default: None
Package
GeoDirectory_Location_Manager
Parameters
- $prefix
- (string) (required) The prefix for all elements.
- Default: None
Change Log
Since: 1.0.0
Source File
geodir_location_autofill_address() is located in geodir_location_manager/geodir_location_hooks_actions.php [Line: 2595]
Source Code
function geodir_location_autofill_address($prefix='') { global $pagenow,$post; $add_google_places_api = false; if(isset($post->post_content) && has_shortcode( $post->post_content, 'gd_add_listing' ) ) {$add_google_places_api = true;} if(((is_page() && get_query_var('page_id') == get_option( 'geodir_add_listing_page' ) ))|| ($add_google_places_api) || (is_admin() && ( $pagenow == 'post.php' || isset($_REQUEST['post_type'])))){ if(get_option('location_address_fill')){}else{?> jQuery(function(){ initialize_autofill_address(); }); var placeSearch, autocomplete; var componentForm = { street_number: 'short_name', route: 'long_name', locality: 'long_name', administrative_area_level_1: 'short_name', country: 'long_name', postal_code: 'short_name' }; function initialize_autofill_address() { // Create the autocomplete object, restricting the search // to geographical location types. autocomplete = new google.maps.places.Autocomplete( /** @type {HTMLInputElement} */(document.getElementById('')), { types: ['geocode'] }); // When the user selects an address from the dropdown, // populate the address fields in the form. google.maps.event.addListener(autocomplete, 'place_changed', function() { fillInAddress(); }); } // [START region_fillform] function fillInAddress() { // Get the place details from the autocomplete object. var place = autocomplete.getPlace(); //blank feilds jQuery('# option[value=""]').attr("selected",true); jQuery("#").trigger("chosen:updated"); jQuery("#").append(''); jQuery('# option[value=""]').attr("selected",true); jQuery("#").trigger("chosen:updated"); jQuery("#").append(''); jQuery('# option[value=""]').attr("selected",true); jQuery("#").trigger("chosen:updated"); jQuery('#').val(''); var newArr = new Array(); newArr[0] = place; geocodeResponse(newArr); geodir_codeAddress(true); if(place.name){jQuery('#').val(place.name);} // Get each component of the address from the place details // and fill the corresponding field on the form. /* for (var i = 0; i < place.address_components.length; i++) { var addressType = place.address_components[i].types[0]; if (componentForm[addressType]) { var val = place.address_components[i][componentForm[addressType]]; document.getElementById(addressType).value = val; } }*/ } // [END region_fillform] // [START region_geolocation] // Bias the autocomplete object to the user's geographical location, // as supplied by the browser's 'navigator.geolocation' object. /*function geolocate() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var geolocation = new google.maps.LatLng( position.coords.latitude, position.coords.longitude); autocomplete.setBounds(new google.maps.LatLngBounds(geolocation, geolocation)); }); } }*/ // [END region_geolocation]