当前位置: 首页>>代码示例>>C#>>正文


C# Location.DistanceTo方法代码示例

本文整理汇总了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;
        }
开发者ID:Reinierr,项目名称:Project4,代码行数:50,代码来源:gmaps.cs

示例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);
 }
开发者ID:topgenorth,项目名称:yegbuildings,代码行数:14,代码来源:BuildingHelper.cs

示例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));
        }
开发者ID:MatejVukosav,项目名称:GdjeMiJeAuto,代码行数:16,代码来源:LocationLogger.cs

示例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;
 }
开发者ID:nagyist,项目名称:bikr,代码行数:20,代码来源:BikrActivityService.cs

示例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);
            }
        }
开发者ID:ibnuda,项目名称:Lok,代码行数:47,代码来源:LocationService.cs

示例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();
        }
开发者ID:SamirHafez,项目名称:HubSpotr,代码行数:20,代码来源:HubActivity.cs


注:本文中的Android.Locations.Location.DistanceTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。