本文整理汇总了C#中Android.Locations.Location.DistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# Location.DistanceTo方法的具体用法?C# Location.DistanceTo怎么用?C# Location.DistanceTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Locations.Location
的用法示例。
在下文中一共展示了Location.DistanceTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnMapReady
public void OnMapReady(GoogleMap googleMap)
{
mMap = googleMap;
LatLng latlng = new LatLng(loc.Latitude, loc.Longitude); //Wijnhaven
CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 15);
mMap.MoveCamera(camera);
MarkerOptions start = new MarkerOptions()
.SetPosition(latlng)
.SetTitle("Uw huidige locatie")
.SetSnippet("U bevind zich hier")
.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueBlue));
mMap.AddMarker(start);
MarkerFactory mFactory = new MarkerFactory(preLoad.csvFT.getMarkers());
float lowest = 99999;
for (Iterator iter = mFactory.getIterator(); iter.hasNext();)
{
FietsTrommel ft = iter.next();
if (ft.xcoord.Length > 0 && ft.ycoord.Length > 0)
{
double lat = Convert.ToDouble(ft.xcoord.Replace('.', ','));
double lon = Convert.ToDouble(ft.ycoord.Replace('.', ','));
Location fietsT = new Location("");
fietsT.Latitude = lat;
fietsT.Longitude = lon;
if (fietsT.DistanceTo(loc) < 500)
{
LatLng coords = new LatLng(lat, lon);
MarkerOptions newMarker = new MarkerOptions()
.SetPosition(coords)
.SetTitle(ft.Straat)
.SetSnippet("Sinds: " + ft.Mutdatum)
.Draggable(true);
mMap.AddMarker(newMarker);
}
if (fietsT.DistanceTo(loc) < lowest)
{
lowest = fietsT.DistanceTo(loc);
closest = ft;
}
}
}
Location closestF = new Location("");
double closLat = Convert.ToDouble(closest.xcoord.Replace('.', ','));
double closLon = Convert.ToDouble(closest.ycoord.Replace('.', ','));
closestF.Latitude = closLat;
closestF.Longitude = closLon;
}
示例2: GetDistanceTo
/// <summary>
/// Returns the distance in metres to the specified location.
/// </summary>
/// <param name="location"> </param>
/// <returns> </returns>
public static int GetDistanceTo(this Building building, Location location)
{
if ((building == null) || (location == null))
{
return 0;
}
var buildingLocation = new Location("me") {Latitude = building.Latitude, Longitude = building.Longitude};
return (int) buildingLocation.DistanceTo(location);
}
示例3: calculateSpeed
double calculateSpeed(long unixTime, double latitude, double longitude)
{
float distance;
Location loc1 = new Location (LocationManager.NetworkProvider);
Location loc2 = new Location (LocationManager.NetworkProvider);
loc1.Latitude = latitude;
loc1.Longitude = longitude;
loc2.Latitude =lastRecord.latitude;
loc2.Longitude =lastRecord.longitude;
distance = loc1.DistanceTo (loc2);
return (distance * 1000 / (unixTime - lastRecord.unixTime));
}
示例4: HandleLocationUpdate
void HandleLocationUpdate(Intent intent)
{
var newLocation = intent.GetParcelableExtra (LocationClient.KeyLocationChanged).JavaCast<Location> ();
if (lastLocation != null) {
if (currentBikingState == BikingState.Biking || currentBikingState == BikingState.InGrace)
currentDistance += lastLocation.DistanceTo (newLocation);
currentFix = newLocation.Time;
} else {
startFix = newLocation.Time;
lastLocation = prevStoredLocation;
if (lastLocation != null)
currentDistance += lastLocation.DistanceTo (newLocation);
prevStoredLocation = null;
}
TripDebugLog.LogPositionEvent (newLocation.Latitude,
newLocation.Longitude,
lastLocation == null ? 0 : lastLocation.DistanceTo (newLocation),
currentDistance);
lastLocation = newLocation;
}
示例5: SendLocationDataToWebsite
protected async void SendLocationDataToWebsite ( Location location )
{
var dateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
var date = new Date (location.Time);
var prefs = this.GetSharedPreferences ("lok", 0);
var editor = prefs.Edit ();
var totalDistance = prefs.GetFloat ("totalDistance", 0f);
var firstTimePosition = prefs.GetBoolean ("firstTimePosition", true);
var distance = 0;
if (firstTimePosition)
editor.PutBoolean ("firstTimePosition", false);
else
{
var prevLocation = new Location ("")
{
Latitude = prefs.GetFloat ("prevLat", 0f),
Longitude = prefs.GetFloat ("prevLong", 0f)
};
distance = (int) location.DistanceTo (prevLocation);
totalDistance += distance;
editor.PutFloat ("totalDistance", totalDistance);
}
editor.PutFloat ("prevLat", (float) location.Latitude);
editor.PutFloat ("prevLong", (float) location.Longitude);
editor.Apply ();
// TODO : add parameters for post requests.
// Hint : using HttpClient();
using (var client = new HttpClient ())
{
var values = new Dictionary<string, string> ()
{
{ "latitude", location.Latitude.ToString() },
{ "longitude", location.Longitude.ToString() },
{ "speed", location.Speed.ToString() },
{ "date", System.Uri.EscapeDataString(DateTime.Now.ToString()) },
{ "locationmethod", location.Provider },
{ "distance", distance.ToString() },
{ "username", prefs.GetString("username", "") },
{ "sessionid", prefs.GetString("sessionId", "") },
{ "accuracy", location.Accuracy.ToString() }
};
var content = new FormUrlEncodedContent (values);
await client.PostAsync (_defaultUploadWebsite, content);
}
}
示例6: OnLocationChanged
public void OnLocationChanged(Location currentLocation)
{
float distanceToHubCenter = currentLocation.DistanceTo(new Location(this.locationProvider)
{
Latitude = CommonData.Hub.Lat,
Longitude = CommonData.Hub.Lng
});
if (distanceToHubCenter > CommonData.Hub.Radius)
new AlertDialog.Builder(this)
.SetTitle("Sorry")
.SetMessage("You fell out of this hubs range")
.SetCancelable(false)
.SetPositiveButton("Leave", async (o, e) =>
{
await CommonData.Hub.Leave();
this.Finish();
})
.Show();
}