Initializing Lightship map with runtime custom coordinates

  • Issue category: Lightship Maps
  • Device type & OS version: Android / iOS
  • Unity version: 2022.3.10f1

Description of the issue:

Hello everyone,

I am a Unity beginner and I’m trying to use Niantic’s Lightship for the first time.
My goal is to initialize the map to focus on a specific location obtained from the device’s GPS coordinates.

I have already created a class responsible for fetching GPS coordinates, and I’ve identified a step in the Awake() method of the LightshipMapView script that appears to be involved:

if (_startAtDefaultLocation)
{
    _unitConverter = InitializeUnitConverter(_defaultLocation);
    SetViewableArea(_unitConverter.MapOrigin, _viewableRadius);
}

To achieve my goal, I’d like to use the class that provides GPS coordinates to pass them to InitializeUnitConverter() and then to SetViewableArea() like this:

{
    SerializableLatLng GPSCoordinate = new SerializableLatLng(GPSCoordProvider.lat, GPSCoordProvider.long);
    _unitConverter = InitializeUnitConverter(GPSCoordinate);
    SetViewableArea(_unitConverter.MapOrigin, _viewableRadius);
}

The issue I’m facing is that I can’t use an external class outside of the Niantic package. In this case, the class I’ve created as part of my assets (GPSCoordProvider) can’t be imported into Niantic’s LightshipMapView class because it belongs to the asset package, not the Niantic package.

I have a feeling that there’s something I haven’t fully understood about how packages work, or there might be a different way to achieve my goal.
If I can figure this out I will be clear on how to carry out the rest .
I would greatly appreciate any ideas or suggestions on this matter.

Hi Lorenzo,

Welcome to Lightship!

For something like this, you wouldn’t edit LightshipMapView.cs directly. Instead, you could attach your own MonoBehaviour to the game object holding the LightshipMapView, capture the LightshipMapView script in the Awake function, and call the #SetViewableArea() function.

LightshipMapView mapView;void Awake(){  mapView = gameObject.GetComponent<LightshipMapView>();}void Start(){  LatLng coords = new LatLng(GPSCoordProvider.lat, GPSCoordProvider.long);  mapView.SetViewableArea(coords, mapView.MapRadius);}

Don’t worry about serializable versions right now. When in doubt, check the API Reference for public members, methods, structures, and classes as those are the anticipated “points of entry” for your external code.

LightshipMapView API Reference:
https://lightship.dev/docs/beta/maps/apiref/Niantic/Lightship/Maps/class_LightshipMapView/

LatLng is a public structure you can import and instantiate: https://lightship.dev/docs/beta/maps/apiref/Niantic/Lightship/Maps/Core/Coordinates/struct_LatLng/

Kind Regards,
Maverick L.

1 Like

This topic was automatically closed 2 hours after the last reply. New replies are no longer allowed.