Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to manipulate a form input use geolocation instead of plain text
    primarykey
    data
    text
    <p>I have a form on my Jquery Mobile page where the user can insert a start-location and a destination. </p> <p>These values will be saved inside the localstorage. Now I'm trying to manipulate the input like this: </p> <p>when you type (for instance) 'current' in the input-box, the user's location will be placed inside the localstorage-database instead of the word 'current'. </p> <p>I already made this script to get the user's location:</p> <pre><code>var geocoder; if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(successFunction, errorFunction); } //Get the latitude and the longitude; function successFunction(position) { var lat = position.coords.latitude; var lng = position.coords.longitude; codeLatLng(lat, lng) } function errorFunction(){ alert("Geocoder failed"); } function initialize() { geocoder = new google.maps.Geocoder(); } function codeLatLng(lat, lng) { var latlng = new google.maps.LatLng(lat, lng); geocoder.geocode({'latLng': latlng}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { console.log(results) if (results[1]) { //formatted address document.getElementById('formatedAddress').innerHTML = results[0].formatted_address; //find country name for (var i=0; i&lt;results[0].address_components.length; i++) { for (var b=0;b&lt;results[0].address_components[i].types.length;b++) { //there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate if (results[0].address_components[i].types[b] == "administrative_area_level_1") { //this is the object you are looking for city= results[0].address_components[i]; break; } } } } } } ); } </code></pre> <p>The 2 input fields:</p> <pre><code>&lt;label for="start"&gt;Startlocation:&lt;/label&gt; &lt;input type="text" name="start" value="" id="start"/&gt; &lt;label for="destination"&gt;Destination:&lt;/label&gt; &lt;input type="text" name="destination" value="" id="destination"/&gt; </code></pre> <p>I'm very new to javascript and jQuery and I can't seem to find a solution to my problem. I hope someone could help me. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload