Changing location in iOS emulator crashes the app?

I’m trying to play around with the GPS feature.

Here’s my code:

var continuousLocation = GeoLocation.observe("changed").map(JSON.stringify);
		function startContinuousListener() {
		    var intervalMs = 1000;
		    var desiredAccuracyInMeters = 10;
		    ml = GeoLocation.startListening(intervalMs, desiredAccuracyInMeters);
		    console.log(JSON.stringify(ml));
		}

startContinuousListener();

console.log(JSON.stringify(continuousLocation));

When I did that, the App asked permission for Geo location, which is fine.

However, when I try to change my location, using the iOS emulator (Debug > Location … some location) the app crashes.

Here it is in action:

Any ideas why this is happening?

Fuse monitor says this about the error:

LOG: Fuse.Scripting.ScriptException: Name: Error
    Error message: Uncaught, unspecified "error" event. (The operation couldn’t be completed. (kCLErrorDomain error 0.))
    File name: FuseJS/EventEmitter.js
    Line number: 228
    JS stack trace: emit@FuseJS/EventEmitter.js:228:15
    
       at Fuse.Scripting.JavaScriptCore.Context.OnError(Fuse.Scripting.JavaScriptCore.JSValueRef)
       at Fuse.Scripting.JavaScriptCore.Object.CallMethod(string,object[])
       at Fuse.Scripting.NativeEventEmitterModule.EmitClosure.Emit(Fuse.Scripting.Context,Fuse.Scripting.Object)
       at Uno.Threading.IDispatcherExtensions.Arg2Invoke`2.Run()
       at Fuse.Reactive.ThreadWorker.RunInner()
       at Fuse.Reactive.ThreadWorker.Run()
       at Uno.Threading.POSIXThread.ReleasingLauncher.Run()
ERROR: 
    Name: Error
    Error message: Uncaught, unspecified "error" event. (The operation couldn’t be completed. (kCLErrorDomain error 0.))
    File name: FuseJS/EventEmitter.js
    Line number: 228
    JS stack trace: emit@FuseJS/EventEmitter.js:228:15
    

Try this

<App>

	<DockPanel>
		<StatusBarBackground Dock="Top" />

		<JavaScript>
		var Observable = require("FuseJS/Observable");
		var GeoLocation = require("FuseJS/GeoLocation");

	    // Immediate
	    var immediateLocation = JSON.stringify(GeoLocation.location);

	    // Timeout
	    var timeoutLocation = Observable("");
	    var timeoutMs = 5000;
	    GeoLocation.getLocation(timeoutMs).then(function(location) {
	    	timeoutLocation.value = JSON.stringify(location);
	    }).catch(function(fail) {
	    	console.log("getLocation fail " + fail);
	    });

	    // Continuous
	    var observedLocation = GeoLocation.observe("changed");
	 	var mapLocation = observedLocation;
	    var continuousLocation = observedLocation.map(JSON.stringify);

	    function startContinuousListener() {
	    	var intervalMs = 1000;
	    	var desiredAccuracyInMeters = 10;
	    	GeoLocation.startListening(intervalMs, desiredAccuracyInMeters);
	    }

	    function stopContinuousListener() {
	    	GeoLocation.stopListening();
	    }

	    module.exports = {
	    	immediateLocation: immediateLocation,
	    	timeoutLocation: timeoutLocation,
	    	continuousLocation: continuousLocation,
	    	mapLocation: mapLocation,

	    	startContinuousListener: startContinuousListener,
	    	stopContinuousListener: stopContinuousListener
	    };
	    </JavaScript>

	    <StackPanel>
	    	<Text>Immediate:</Text>
	    	<Text Value="{immediateLocation}" />

	    	<Text>Timeout:</Text>
	    	<Text Value="{timeoutLocation}" />

	    	<Text>Continuous:</Text>
	    	<Text Value="{continuousLocation}" />

	    	<Button Text="Start continuous listener" Clicked="{startContinuousListener}" />
	    	<Button Text="Stop continuous listener" Clicked="{stopContinuousListener}" />

	    	<NativeViewHost>
	    		<Select Data="{mapLocation}">
	    		<MapView Height="300" Latitude="{latitude}" Longitude="{longitude}" Zoom="18">
	    			<MapMarker Latitude="{latitude}" Longitude="{longitude}" Label="Me" />
	    		</MapView>
	    		</Select>
	    	</NativeViewHost>
	    </StackPanel>

	</DockPanel>
</App>

Same thing happens. If it’s running on the immediate listener, it works.

If I change this to the continuous listener, as soon as I change the GPS location, it crashes.

Here’s the video.

Hey!

I think the reason the app crashes is that a GeoLocation error occurs without anyone listening to the "error" event. See the EventEmitter docs for more info.

If you add a listener to the "error" event, e.g. using GeoLocation.on("error", function(err) { ... }) you can handle the error yourself and no exception will be thrown. I’m not entirely sure why that error occurs, but it comes from the native APIs so it’s somewhat out of our control.

I’ll make a note on improving the documentation in this area.

I have the same problem. My app do not crash when I listen to “Geolocation.on(“error”)”

Error message is:
"The operation couldn’t be completed (kCLErrorDomain error 0). Ref this case as well:

I have reported the same problem here:
https://www.fusetools.com/community/forums/bug_reports/not_able_to_update_geolocaton_continous

Is the problem not solved by adding an error handler?

Ok, let me check.

We’re in business!
It doesnt crash any more, and I get this error: The operation couldn’t be completed. (kCLErrorDomain error 0.)

But at least it works! :slight_smile:
Thanks guys!

Ok, new issue:
The error is caught with the error handler, however, the location is not displayed. Therefore the GeoLocation.onChanged function never fires?

So technically nothing happens and geolocation does not work on iOS?