mapbox-unity-sdk icon indicating copy to clipboard operation
mapbox-unity-sdk copied to clipboard

Directions - How to put the second direction marker on specific point on the map with Lan & Lon

Open cavanju opened this issue 4 years ago • 6 comments

I am developing a City tour app - If the user presses on a button (directions to X) He can see himself on the map and the direction to a specific point on the map

I have succeeded in attaching the first marker to the users location but I can only place the second marker by touch. I want this to be coded so that the second marker is predefined.

As you can see on the image below, it seems to be working however I placed the second marker with touch as it is in the Directions example of Mapbox SDK

image

I tried SpawnOnMap and afterwards attaching the second Wapoint to this object but this doesn't work

cavanju avatar Nov 25 '20 13:11 cavanju

@cavanju so you have the player position and target latlng right? You can use AbstractMap.GeoToWorldPosition to convert latlng into unity3d space position and place your marker. but of course route query uses latlng itself.

brnkhy avatar Nov 25 '20 13:11 brnkhy

@brnkhy Thank you for the quick response. I have searched around a bit but I do not really understand how to use this AbstractMap.GeoToWorldPosition(LatLong, true); ?

So I make a new script and attach it to my second waypoint and this script needs the AbstractMap.GeoToWorldPosition. But I don't really understand how to use it?

thanks in advance

cavanju avatar Nov 25 '20 14:11 cavanju

@brnkhy This is what I have until now

` using Mapbox.Unity.Map; using UnityEngine; using Mapbox.Utils; using Mapbox.Unity.Utilities; public class WaypointTarget : MonoBehaviour { [SerializeField] AbstractMap _map;

    [SerializeField]
	[Geocode]
	string[] _locationStrings;
	Vector2d[] _locations;
	
	void Start()
	{
        	_locations = new Vector2d[_locationStrings.Length];

            for (int i = 0; i < _locationStrings.Length; i++)
		{
			var locationString = _locationStrings[i];
			_locations[i] = Conversions.StringToLatLon(locationString);
            transform.localPosition = _map.GeoToWorldPosition(_locations[i], true);
		
        }
        //var map = Instance.mapManager;
		//transform.localPosition = map.GeoToWorldPosition(LocationProvider.CurrentLocation.LatitudeLongitude);
        
        
  
	}

}`

cavanju avatar Nov 25 '20 14:11 cavanju

But it is not working sadly enough

cavanju avatar Nov 25 '20 14:11 cavanju

@cavanju what's not working exactly? I'll need more information. That code looks like it'll use only the last coordatinate in _locations array for example. I would also suggest checking latlng and lnglat order of the locations.

brnkhy avatar Dec 05 '20 12:12 brnkhy

i have a same problem too... if you solve it plz help me..

Heesunni avatar May 12 '21 18:05 Heesunni