google maps api geolocation doesn't update on timeout - google-maps-api-3

I know this is probably not the most performant code possible, but if anyone can help I'd really appreciate that.
I'm working on a web-application that's supposed to locate the user's position with the google maps api. For this I created an UI control that starts the tracking of the user's current position and starts a timeout function that should update the position of the user. Everything works fine, but I testet the app when moving around and the geolocation doesn't change with the timeout, it always just shows the position of the first loop. I have to click on the UI control again to update the position.
These are the functions I adapted from the Google developer sites:
The function to detect the position:
//locate the user via GPS by checking geopositioning
function locateUser(geoLoc) {
var geoSuccess = function(position, map) {
startPos = position;
userLat = startPos.coords.latitude;
userLon = startPos.coords.longitude;
geoLoc = {lat : userLat ,lng : userLon};
};
var geoError = function(error, map) {
geoLoc = null;
//console.log('Error occurred. Error code: ' + error.code);
// error.code can be:
// 0: unknown error
// 1: permission denied
// 2: position unavailable (error response from location provider)
// 3: timed out
};
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
};
locateUser(geoLoc);
I'm using the variable "geoLoc" to get latitude and longitude within the map api.
This is the function that is called by a click on the UI-control and that starts the timeout:
//set the marker for the current position to the geolocation, when geolocation is possible
function setUserPosition(map, geoLoc, controlUI) {
//get the geolocation
locateUser(geoLoc);
//check if the position marker for the user position is already attached
if (positionSet == false) {
//if the position marker is not attached (first time user hits the UI control), generate and attach it nad notify the user that it's position is tracked
positionSet = true;
var userpos = {
url: "https://myhost.com/mygraphic.png", // url
scaledSize: new google.maps.Size(45,45), // scaled size
origin: new google.maps.Point(0,0), // origin
anchor: new google.maps.Point(23,23) // anchor
};
positionMarker = new google.maps.Marker({
position: geoLoc,
map: map,
zIndex: 100,
icon: userpos
});
}
//Check if geolocation is possible.
//If geolocation is not possible, hide the location marker and change the UI control's state back to default, but try again in three seconds.
if(geoLoc == null) {
controlUI.style.backgroundColor = '#4485F8';
controlUI.style.backgroundImage = "url('https://myhost.com/oldbackgroundimage.png')";
moveControl = false;
} else {
//If geolocation is possible, make the position marker visible, set it to the located position and cahnge the UI's state to "active".
posMark = positionMarker;
posMark.setPosition(geoLoc);
controlUI.style.backgroundColor = '#eeeef4';
controlUI.style.backgroundImage = "url('https://myhost.com/newbackgroundimage.png')";
moveControl = true;
}
map.panTo(geoLoc);
//check if the user hit the button to start the positiontracking and loop the function if so
if(moveControl == true) {
timeoutControl = setTimeout(function(){setUserPosition(map, geoLoc, controlUI)}, 3000);
} else if(moveControl == false) {
clearTimeout(timeoutControl);
}
}
And this is the function for the UI-control within the init-map function:
controlUI.addEventListener('click', function() {
//check if the user tapped the UI to locate the current position
if(moveControl == false) {
moveControl = true;
locateUser();
//if geolocation is not possible, open an alert to notify the user
if(geoLoc == null) {
alert("No geolocation :(");
} else {
//if geolocation is possible, set the UI control to the "active" state and start the interval to locate the user permanently (every three seconds)
controlUI.style.backgroundColor = '#eeeef4';
controlUI.style.backgroundImage = "url('https://myhost.com/newbackgroundimage.png')";
setUserPosition(map, geoLoc, controlUI);
//Show the Position marker
posMark.setMap(map);
}
//if the user has tapped the UI control and is in "location-mode" this tap stops the location mode and sets everything back into default state
} else if(moveControl == true) {
clearTimeout(timeoutControl);
moveControl = false;
controlUI.style.backgroundColor = '#4485F8';
controlUI.style.backgroundImage = "url('https://myhost.com/oldbackgroundimage.png')";
//Hide the Position marker
posMark.setMap(null);
}
});
I ran the script with an alert to display geoLoc within the geoSucess function of the locateUser function and it gets executed every time the timeout runs over the code and always fires geoLoc with data, but always only the position the user had when he first clicked the UI control.
Can anybody help and does know why the position is not updated within the timeout or maybe know how it would be updated?
Thanks a lot & kind regards,
Philipp

Related

Xamarin.Forms How to display progress indicator while sound recording/playback takes place

I would like to display a progress indicator while recording sound in my app.
The amount of time allocated for the recording is predefined. I set that up in code, lets say 10 seconds maximum recording time, but the user can stop the recording in less time, and of course he progress indicator would stop and reset.
I have been trying to make it work right could you please offer some guidance.
Note: I am using the NateRickard AudioRecorder nuget package.
if (!recorder.IsRecording)
{
buttonRecord.IsEnabled = false;
buttonPlay.IsEnabled = false;
DependencyService.Get<IAudioService>().PrepareRecording();
// start recording
var recordTask = await recorder.StartRecording();
// set up progress bar
//progressBarRecordTime.Progress = 1.0;
//await progressBarRecordTime.ProgressTo(1.0, 10000, Easing.Linear);
buttonRecord.Text = "Stop Recording";
buttonRecord.IsEnabled = true;
// get the recorded file
var recordedAudioFile = await recordTask;
buttonRecord.Text = "Record";
buttonPlay.IsEnabled = true;
if (recordedAudioFile != null)
{
var recordingFileDestinationPath = Path.Combine(FileSystem.AppDataDirectory, AppConstants.CUSTOM_ALERT_FILENAME);
if (File.Exists(recordingFileDestinationPath))
{
File.Delete(recordingFileDestinationPath);
}
File.Copy(recordedAudioFile, recordingFileDestinationPath);
}
}
Place an ActivityIndicator (name it ind) in your xaml code (view)
At the top of your code above:
ind.IsRunning = true;
//
if (!recorder.IsRecording)
//
when you are done, add this below your code
//
}
File.Copy(recordedAudioFile, recordingFileDestinationPath);
}
}
ind.IsRunning = false;

places api Unable to get property 'address_components' of undefined or null reference

working with the google places api and cannot figure why autocomplete is returning undefined here on call to get places.
what developer tools shows is.
address_components is what should be returned on a call to autocomplete.getPlace
Unable to get property 'address_components' of undefined or null reference
function initAutoCompleteDynamic() {
var slideID = 99;
var idx = 99 - slideID;
var propcount = 5;
for (var i = 0; i < propcount; i++) {
var propaddress = "prop1address" + i;
var autocomplete = autocomplete + i;
autocomplete = new google.maps.places.Autocomplete(
document.getElementById(propaddress)),
{ types: ['geocode'] };
autocomplete.addListener('place_changed', fillinAddressDynamic);
}
}
and in fillinAddressDynamic
var place=autocomplete.getPlace():
for (var i = 0; i < place.address_components.length; i++) {
alert("i am in the loop");
var addressType = place.address_components[i].types[0];
var field = addressType;
var completeaddress1 = '';
var propaddress = 'prop1address' + i;
var strnum = 'streetnumber' + i;
CR(i);//calling component resolver.
if (componentFormProduction[addressType]) {
var val = place.address_components[i][componentFormProduction[addressType]];
document.getElementById(CR[addressType]).value = val;
if (field == "street_number") {
var streetnum = document.getElementById(strnum).value = val;
}
if (field == "route") {
if (streetnum) {
completeaddress1 = streetnum + ' ' + val;
}
else {
completeaddress1 = val;
}
document.getElementById('prop1address0').value = completeaddress1;
}
}
}
This would happen if the user (or you) hits Enter without clicking on a suggestion.
Typically the sequence of event is like this:
user enters input
JavaScript queries Autocomplete for suggestions
user clicks on a suggestion
JavaScript queries Details, replaces user input with Details responses' fields (incl. address_components) and fires the places_changed event
handler for places_changed will obtain the Place object from Details response by calling getPlace()
However, it may also be like this:
user enters input
JavaScript queries Autocomplete for suggestions
user disregards suggestions and hits Enter without clicking on one
JavaScript fires the places_changed event without querying Details or modifying user input
handler for places_changed calls getPlace() and gets a nearly empty Place object, with only the name field containing the raw user input.
It is for you to decide what to do with raw user input, here are some examples:
This tool uses the JavaScript Geocoding service to search for that input:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/
This example (address form) does nothing with it:
https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete-addressform
This (very basic) example will show an error message reporting no details:
https://google-developers.appspot.com/maps/documentation/javascript/examples/full/places-autocomplete

redirect chrome users in new window

I have tried this but its not what I want ....
also this code does not works
<%= Html.ActionLink("Paypal", "HowItWorksRedirect", null, new { #class = "Paypal" })%>
public ActionResult HowItWorksRedirect()
{
return Redirect("https://www.paypal-deutschland.de/sicherheit/schutzprogramme.html");
}
I want to redirect all chrome users to new window
I want to keep users on my website but also redirect them to new window... (600x800 or something like this)
How can I do that?
Opening a new window (or tab, depending on browser settings) is easy:
With a link, you can use
LINK
Or you can use JS:
window.open('http://google.com', 'Google', 'width=800, height=600');
With the help of navigator.userAgent you can get the User Agent and use a regex to find out if the user is using Chrome
if(/Chrome/.test(navigator.userAgent)) { /* CHROME USER */ }
<script>
//specify page to pop-under
var popunder="http://wow.ge/"
//specify popunder window features
//set 1 to enable a particular feature, 0 to disable
var winfeatures="width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0"
//Pop-under only once per browser session? (0=no, 1=yes)
//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session=0
///No editing beyond here required/////
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadornot(){
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}
function loadpopunder(){
win2=window.open(popunder,"",winfeatures)
win2.blur()
window.focus()
}
if (once_per_session==0)
loadpopunder()
else
loadornot()
</script>
but browsers blocking that !

Music player in Actionscript 3.0

I already added a stop button with autoplay but I need to make it so when you click the button again after you had stopped it, the music starts playing.
Source code:
var music:Sound = new Sound(new URLRequest("calmingsong.mp3"));
var sc:SoundChannel = music.play();
button1.addEventListener(MouseEvent.CLICK, stopMusic);
function stopMusic(e:Event):void
{
sc.stop();
}
If you just want to play the sound over from the beginning, just call the Sound object's play() method again (you get a new SoundChannel object when you do this).
If you'd like to resume playing the sound at the point where the user stopped it, you'll need to add additional variables to store the current "playback state"... Something like this:
var music:Sound = new Sound(new URLRequest("calmingsong.mp3"));
var sc:SoundChannel = music.play();
var startPosition:Number = 0;
var isPlaying = true; // default to true cause you auto play...
button1.addEventListener(MouseEvent.CLICK, togglePlayback);
function togglePlayback(e:Event):void
{
if (isPlaying)
{
startPosition = sc.position;
sc.stop();
isPlaying = false;
}
else
{
sc = music.play(startPosition);
isPlaying = true;
}
}

LinkBar button / label click event transition

I have created a linkbar with two labels. Now, I need to keep a track of the label clicks.
10
100
i.e. If in the beginning "First" is clicked, the details will be displayed. After that, if without submitting the details, "Second" is clicked then an alert message should come to inform the user that "First is still in progress, do you want to cancel and begin Second operation". Vice-versa for Second to First transition. I need to know how to write events to keep track of which button clicked.
maybe....
var inProgress:Boolean = false;
var clickedButton:Button;
private function clickButtonHandler(event:MouseEvent):void{
if(clickedButton != null){
if(clickedButton != event.currentTarget && inProgress){
//handle alert
}
}
else{
clickedButton = event.currentTarget;
}
inProgress = true;
}
private function sumbitDetailsHandler(event:Event):void{
inProgress = false;
clickedButton = null;
}

Resources