- This topic has 4 replies, 2 voices, and was last updated 11 years, 5 months ago by support-octavio.
-
AuthorPosts
-
benlMemberI’ve been plagued by this issue for a few days now and I’m hoping someone here may be able to help. Right now I attempt to determine a users location before a form (login) is submitted using the code below.
phoneui.preSubmitForm_m1_xapp = function(form) { if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(onPositionUpdate, onError,{timeout: 10000}) } else { onError() } //It is at this point I need to determine if no location was found either via the geo location or zip code form method return false, else return true true; }
function onPositionUpdate(position) { var lat = position.coords.latitude; window.localStorage.setItem("currentlat",lat) var long = position.coords.longitude; window.localStorage.setItem("currentlong",long) } function onError(err) { var zipcode=prompt("We couldn't get your location, let's try something else. Enter your zip code below.","Zip Code"); var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': zipcode}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var latitude = results[0].geometry.location.lat(); var longitude = results[0].geometry.location.lng(); window.localStorage.setItem("currentlat",latitude); window.localStorage.setItem("currentlong",longitude); } }); }
I am having trouble returning back to the parent Mobione function whether or not their location was found either from the geo location method or the zip code dialog method. If neither function was a success I need to throw false in the primary function to stop the user from entering the app. Any help would be greatly appreciated!
benlMemberAnyone have any ideas on this? Essentially I need a way to stop the form from submitting if I can’t get a user’s location. Cincy, wayne, octavio, etc, any help would be greatly appreciated.
support-octavioMemberHi,
Have you tried to return false if the zipcode search doesn’t return results in the onError function and use that value in your preSubmitForm_m1_xapp? something like this:
phoneui.preSubmitForm_m1_xapp = function(form) {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(onPositionUpdate, onError,{timeout: 10000})
}
else {
if(!onError()) // if the onError function returns false
return false;
}geocoder.geocode( { ‘address’: zipcode}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
window.localStorage.setItem(“currentlat”,latitude);
window.localStorage.setItem(“currentlong”,longitude);
}
else{
return false;
}
});
benlMemberOctavio,
Thanks for the reply! That solution worked for the second half of the primary if function and I moved a few things around and I was able to get it to work all the way through. (Of course it was something simple.)
support-octavioMemberHi benl,
I am glad to help. Closing thread since you have solved the problem.
-
AuthorPosts