Skip to content

Instantly share code, notes, and snippets.

@garethpaul
Created July 24, 2017 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethpaul/c10878719788728631016a42e6abcf32 to your computer and use it in GitHub Desktop.
Save garethpaul/c10878719788728631016a42e6abcf32 to your computer and use it in GitHub Desktop.
namespace Mapbox.Examples.LocationProvider
{
using Mapbox.Unity.Map;
using UnityEngine;
using Mapbox.Unity.Location;
/// <summary>
/// Override the map center (latitude, longitude) for a MapController, based on the DefaultLocationProvider.
/// This will enable you to generate a map for your current location, for example.
/// </summary>
public class BuildMapAtLocation : MonoBehaviour
{
[SerializeField]
AbstractMap _map;
ILocationProvider _locationProvider;
ILocationProvider LocationProvider
{
get
{
if (_locationProvider == null)
{
_locationProvider = LocationProviderFactory.Instance.DefaultLocationProvider;
}
return _locationProvider;
}
}
void Start()
{
LocationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated;
}
void LocationProvider_OnLocationUpdated(object sender, Unity.Location.LocationUpdatedEventArgs e)
{
LocationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated;
_map.CenterLatitudeLongitude = new Mapbox.Utils.Vector2d (37.790446, -122.404503);
//_map.CenterLatitudeLongitude = e.Location;
_map.enabled = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment