All docschevron-rightUnity SDKchevron-rightarrow-leftGuideschevron-rightAdd markers

Add markers

SpawnOnMap provides an outline of placing custom markers. It uses the Start() function to calculate initial marker positions, then uses Update() to update those positions every time the map changes (either from zooming or panning).

void Start()
  _locations = new Vector2d[_locationStrings.Length];
  _spawnedObjects = new List<GameObject>();
  for (int i = 0; i < _locationStrings.Length; i++)
    var locationString = _locationStrings[i];
    _locations[i] = Conversions.StringToLatLon(locationString);
    var instance = Instantiate(_markerPrefab);
    instance.transform.localPosition = _map.GeoToWorldPosition(_locations[i], true);
+   instance.transform.localScale = new Vector3(_spawnScale, _spawnScale, _spawnScale);

private void Update()
  int count = _spawnedObjects.Count;
  for (int i = 0; i < count; i++)
    var spawnedObject = _spawnedObjects[i];
    var location = _locations[i];
    spawnedObject.transform.localPosition = _map.GeoToWorldPosition(location, true);

Use the SpawnOnMap script

To use the SpawnOnMap script, add it as a Component to a Map GameObject. Below is a description of the variables.

MapMap object on which to place custom markers.
Location StringsList of locations in latitude, longitude format.
Spawn ScaleScale of spawned markers. Applied as uniform scale in all directions.
Custom PrefabPrefab that will be spawned on the map as the marker.
Was this page helpful?