Well, I have the following problem to solve .. I'm using the google API to pick up the user's current geolocation, but by clicking on the icon that takes the geolocation the form is only submitted if you click on the input and press enter, but I need it to be automatic. 1 - Or press the enter automatically. 2 - Or submit it in the form automatically. already tested the following codes but does not return the expected result:
//for submit
jQuery("form#searchUnits").submit();
//for keypress Enter
var e = jQuery.Event( "keypress", { which: 13 } );
jQuery('form#searchUnits .units-input').trigger( e );
This code is inside a jQuery (document) .click (function (e) {}); with e.preventDefault (); then everything happens without reloading p. Thank you!
// Geolocation Google Maps API
jQuery('#getLocation').on('click', function ( e ) {
e.preventDefault();
if ( navigator.geolocation ) {
navigator.geolocation.getCurrentPosition( function ( position ) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var geocoder = new google.maps.Geocoder;
geocoder.geocode({ 'location': pos }, function ( results, status ) {
if ( status === 'OK' ) {
if ( results[1] ) {
jQuery( '#getLocation' ).parent().find( 'input' ).val( results[1].formatted_address );
jQuery( '#getLocation' ).parent().find( 'input' ).attr( 'lat', pos.lat );
jQuery( '#getLocation' ).parent().find( 'input' ).attr( 'lng', pos.lng );
//arrayLat();
} else {
//window.alert('No results found');
}
} else {
}
});
}, function () {
alert('É necessário ativar a geolocalização para utilizar este recurso!');
});
} else { }
jQuery( "html, body" ).click();
jQuery( "form#searchUnits .units-input" ).focus();
jQuery("form#searchUnits").submit();
var e = jQuery.Event( "keypress", { which: 13 } );
jQuery('form#searchUnits .units-input').trigger( e );
});