1 (edited by thorntonp72 2022-12-30 04:07:27)

Topic: Unable to get map to move/zoom to current location on start / anytime


I am using the below script attached to an object on my application, which grabs the users current location, but I cam not able to get the Map to move to this position and zoom in a little when the application opens. I also save the position to a playerpref item and use that to speed up the process on start with the Latitude and Longititude coords.

I have tried to implement this with the http://infinity-code.com/atlas/online-m … ample.html but it just does not go anywhere or move on start.

Is there a better example on how to do this? I am also going to try to implement a second / third marker into the map for other users positions so maybe something than can incorporate that also? I have seen the tutorial youtube v=Yl5K_Wr6Umk so that might work, but the initial location go to and zoom is my main issue at the moment.

SCRIPT for getting location of mobile user
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Android;

public class GPS : MonoBehaviour
    public Text gpsOut;
    public bool isUpdating;
    private void Update()
        if (!isUpdating)
            isUpdating = !isUpdating;
    IEnumerator GetLocation()
        if (!Permission.HasUserAuthorizedPermission(Permission.FineLocation))
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
            yield return new WaitForSeconds(10);

        // Start service before querying location

        // Wait until service initializes
        int maxWait = 10;
        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
            yield return new WaitForSeconds(1);

        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
            gpsOut.text = "Timed out";
            print("Timed out");
            yield break;

        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
            gpsOut.text = "Unable to determine device location";
            print("Unable to determine device location");
            yield break;
            gpsOut.text = "Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + 100f + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp;
            // Access granted and location value could be retrieved
            print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);

        // Stop service if there is no need to query location updates continuously
        isUpdating = !isUpdating;


Re: Unable to get map to move/zoom to current location on start / anytime


Use OnlineMaps.SetPositionAndZoom.
https://infinity-code.com/doxygen/onlin … 3675112887

Something like:

var lastData = Input.location.lastData;
OnlineMaps.instance.SetPositionAndZoom(lastData.longitude, lastData.latitude, SOME_ZOOM);
Kind Regards,
Infinity Code Team.

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