Topic: GPS emulation doesn't work

I try to use GPS emulation running application in Unity3D Editor. I have checked "Use GPS Emulator" and entered Latitude: 37.61713, Longitude: 55.75581, Compass: 0 in OnlineMapsLocationService component.

But the following code

float lon, lat;
OnlineMapsLocationService.instance.GetLocation (out lon, out lat);

returns zeroes in lon and lat variables.

What do I need to do to start GPS emulation?

Re: GPS emulation doesn't work

Hello.

Most likely the problem is that you are trying to get a location in Start.
GPS is not available in Start, and GPS emulator too.

Use OnlineMapsLocationServiceBase.OnLocationInited or OnlineMapsLocationServiceBase.OnLocationChanged to determine that GPS (or emulator) is initialized.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

3 (edited by YanaAzur 2017-11-29 10:15:47)

Re: GPS emulation doesn't work

Alex, thank you for the reply. I have tried the following code:

    public Text txtGPS;

    void Start () {
        ...
        OnlineMapsLocationService.instance.OnLocationChanged += OnLocationChanged;
    }

    private void OnLocationChanged(Vector2 position) {
        float lon, lat;
        OnlineMapsLocationService.instance.GetLocation (out lon, out lat);
        txtGPS.text = " Lat: "+lat+"\nLon: "+lon;
    }

There are my OnlineMapsLocationService component settings:
Desired Acuracy (meters): 1
Compass Threshold: 8
Find Location By IP: [checked]
Update Map Position: [checked]
Update Distance: 2
Auto Stop On Input: [not checked]
Restore After (sec): 10
Create Marker: [not checked]
Use GPS Emulator: [checked]
Disable Emulator on Publish: [checked]
Latitude: 55.7522
Longitude: 37.6156
Compass (0-360): 0

Unfortunately, there were no one OnLocationChanged() call running in Unity3D Editor during 10 minutes. On the phone the code works fine, GPS coordinates are shown and changing.

Re: GPS emulation doesn't work

I just checked it out.
OnLocationChanged works correctly.
The problem is that the name of GetLocation method does not match the behavior, and is misleading.
This method is used to internally get coordinates from Unity Location Service.
The user can override this method if he wants to get coordinates from another source, for example from the device's sensors directly.
We'll figure out how to fix this (rename or change the visibility of the method).

The right way to get the coordinates is:

Vector2 position = OnlineMapsLocationService.instance.position;
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.