本文整理汇总了C#中GeoCoordinateWatcher.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# GeoCoordinateWatcher.Stop方法的具体用法?C# GeoCoordinateWatcher.Stop怎么用?C# GeoCoordinateWatcher.Stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeoCoordinateWatcher
的用法示例。
在下文中一共展示了GeoCoordinateWatcher.Stop方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainPage
public MainPage()
{
InitializeComponent();
_watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
_watcher.MovementThreshold = 20;
_watcher.StatusChanged += (sender, args) =>
{
if (args.Status == GeoPositionStatus.Ready)
{
try
{
GeoCoordinate coordinates = _watcher.Position.Location;
DevCenterAds.Longitude = coordinates.Longitude;
DevCenterAds.Latitude = coordinates.Latitude;
}
finally
{
_watcher.Stop();
}
}
};
_watcher.Start();
LayoutUpdated += OnLayoutUpdated;
}
示例2: getCurrent
public static void getCurrent(LocationDelegate callback)
{
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
watcher.MovementThreshold = 20; // use MovementThreshold to ignore noise in the signal
//watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(
(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) =>
{
System.Diagnostics.Debug.WriteLine(e.Position.Location);
watcher.Stop();
callback(e.Position.Location);
});
watcher.Start();
}
示例3: OnNavigatedTo
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (serviceClient != null) return;
var loginProvider = (MobileServiceAuthenticationProvider) int.Parse(NavigationContext.QueryString["provider"]);
var nickname = NavigationContext.QueryString["nick"];
var group = NavigationContext.QueryString["group"];
this.group.Text = group;
serviceClient = new ServiceClient {AuthenticationProvider = loginProvider};
var me = new Ninja
{
GroupName = group,
NickName = nickname
};
var watcher = new GeoCoordinateWatcher();
watcher.PositionChanged += (sender, args) => {
var lat = /*args.Position.Location.Latitude*/ 55.7091;
var lon = /*args.Position.Location.Longitude*/ 013.1982;
var geoCoordinate = new GeoCoordinate(lat, lon);
map.SetView(geoCoordinate, 6, MapAnimationKind.Linear);
me.Latitude = lat;
me.Longitude = lon;
serviceClient.LocateNinjas(me, ninjas => Dispatcher.BeginInvoke(delegate
{
var children = MapExtensions.GetChildren(map);
foreach (var ninja in ninjas)
{
var ninjaLocation = new GeoCoordinate(ninja.Latitude, ninja.Longitude);
var pushpin = new Pushpin { GeoCoordinate = ninjaLocation, Content = ninja.NickName };
children.Add(pushpin);
}
children.Add(new Pushpin {GeoCoordinate = geoCoordinate, Content = me.NickName, Background = new SolidColorBrush(Colors.Orange) });
}));
watcher.Stop();
};
watcher.Start();
}
示例4: getCurrentLatLonRage
public void getCurrentLatLonRage()
{
/* Get Current location */
GeoCoordinateWatcher getPosition = new GeoCoordinateWatcher();
int geoGetTry = 3; //times...
bool gotGeoRespond = false;
while (geoGetTry-- > 0 && gotGeoRespond == false)
{
gotGeoRespond = getPosition.TryStart(false, TimeSpan.FromMilliseconds(1000));
}
/*
* Only update current location if is good location
* else just use what we have before
*/
if (gotGeoRespond == true)
{
lat = (float)getPosition.Position.Location.Latitude;
lon = (float)getPosition.Position.Location.Longitude;
}
getPosition.Stop();
getPosition.Dispose();
latLon position = new latLon(lat, lon);
double r = (double)App.distancesMeter[App.ReadSettings.radiusMetersIndx] / (double)App.R;
double latRad = mathPlus.DegreeToRadian((double)position.getLat());
latStart = (float)mathPlus.RadianToDegree(latRad - r);
latEnd = (float)mathPlus.RadianToDegree(latRad + r);
double lonRad = mathPlus.DegreeToRadian((double)position.getLon());
double tLon = Math.Asin(Math.Sin(r) / Math.Cos(latRad));
lonStart = (float)mathPlus.RadianToDegree(lonRad - tLon);
lonEnd = (float)mathPlus.RadianToDegree(lonRad + tLon);
}
示例5: GetEnabled
private static bool GetEnabled()
{
GeoCoordinateWatcher w = new GeoCoordinateWatcher();
try
{
w.Start(true);
bool enabled = (w.Permission == GeoPositionPermission.Granted && w.Status != GeoPositionStatus.Disabled);
w.Stop();
return enabled;
}
catch (Exception)
{
return false;
}
finally
{
w.Dispose();
}
}
示例6: Initialize
/// <summary>
/// Initializes the application context for use through out the entire application life time.
/// </summary>
/// <param name="frame">
/// The <see cref="T:Microsoft.Phone.Controls.PhoneApplicationFrame" /> of the current application.
/// </param>
public static void Initialize(PhoneApplicationFrame frame)
{
// Initialize Ioc container.
var kernel = new StandardKernel();
kernel.Bind<Func<Type, NotifyableEntity>>().ToMethod(context => t => context.Kernel.Get(t) as NotifyableEntity);
kernel.Bind<PhoneApplicationFrame>().ToConstant(frame);
kernel.Bind<INavigationService>().To<NavigationService>().InSingletonScope();
kernel.Bind<IStorage>().To<IsolatedStorage>().InSingletonScope();
kernel.Bind<ISerializer<byte[]>>().To<BinarySerializer>().InSingletonScope();
kernel.Bind<IGoogleMapsClient>().To<GoogleMapsClient>().InSingletonScope();
kernel.Bind<IDataContext>().To<DataContext>().InSingletonScope();
kernel.Bind<IConfigurationContext>().To<ConfigurationContext>().InSingletonScope();
Initialize(kernel);
// Initialize event handlers and other properties.
GeoCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High) {MovementThreshold = 10D};
((DataContext) Data).AppVersion = new AssemblyName(Assembly.GetExecutingAssembly().FullName).Version;
Data.PreventScreenLock.ValueChanged += (old, @new) => { PhoneApplicationService.Current.UserIdleDetectionMode = @new ? IdleDetectionMode.Disabled : IdleDetectionMode.Enabled; };
Data.UseLocationService.ValueChanged += (old, @new) =>
{
if (@new) GeoCoordinateWatcher.Start();
else GeoCoordinateWatcher.Stop();
};
IsNetworkAvailable = NetworkInterface.GetIsNetworkAvailable();
NetworkChange.NetworkAddressChanged += (s, e) => IsNetworkAvailable = NetworkInterface.GetIsNetworkAvailable();
}
示例7: RenderEditTaskField
private void RenderEditTaskField(Task task, FieldType fieldType)
{
PropertyInfo pi;
// make sure the property exists on the local type
try
{
pi = task.GetType().GetProperty(fieldType.Name);
if (pi == null)
return; // see comment below
}
catch (Exception)
{
// we can't do anything with this property since we don't have it on the local type
// this indicates that the phone software isn't caught up with the service version
return;
}
// get the value of the property
var val = pi.GetValue(task, null);
ListBoxItem listBoxItem = new ListBoxItem();
StackPanel EditStackPanel = new StackPanel();
listBoxItem.Content = EditStackPanel;
EditStackPanel.Children.Add(
new TextBlock()
{
Text = fieldType.DisplayName,
Style = (Style)App.Current.Resources["PhoneTextNormalStyle"]
});
// create a textbox (will be used by the majority of field types)
double minWidth = App.Current.RootVisual.RenderSize.Width;
if ((int)minWidth == 0)
minWidth = ((this.Orientation & PageOrientation.Portrait) == PageOrientation.Portrait) ? 480.0 : 800.0;
TextBox tb = new TextBox() { DataContext = taskCopy, MinWidth = minWidth, IsTabStop = true };
tb.SetBinding(TextBox.TextProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
bool notMatched = false;
// render the right control based on the type
switch (fieldType.DisplayType)
{
case "String":
tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
tb.TabIndex = tabIndex++;
tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
EditStackPanel.Children.Add(tb);
break;
case "TextBox":
tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
tb.AcceptsReturn = true;
tb.TextWrapping = TextWrapping.Wrap;
tb.Height = 300;
tb.TabIndex = tabIndex++;
tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
EditStackPanel.Children.Add(tb);
break;
case "Phone":
case "PhoneNumber":
tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.TelephoneNumber } } };
tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
tb.TabIndex = tabIndex++;
StackPanel innerPanel = RenderEditTaskImageButtonPanel(tb);
ImageButton imageButton = (ImageButton)innerPanel.Children[1];
imageButton.Click += new RoutedEventHandler(delegate
{
PhoneNumberChooserTask chooser = new PhoneNumberChooserTask();
chooser.Completed += new EventHandler<PhoneNumberResult>((sender, e) =>
{
if (e.TaskResult == TaskResult.OK && e.PhoneNumber != null && e.PhoneNumber != "")
pi.SetValue(task, e.PhoneNumber, null);
});
chooser.Show();
});
EditStackPanel.Children.Add(innerPanel);
break;
case "Website":
tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Url } } };
tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
tb.TabIndex = tabIndex++;
tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
EditStackPanel.Children.Add(tb);
break;
case "Email":
tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.EmailSmtpAddress } } };
tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
tb.TabIndex = tabIndex++;
tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
innerPanel = RenderEditTaskImageButtonPanel(tb);
imageButton = (ImageButton)innerPanel.Children[1];
imageButton.Click += new RoutedEventHandler(delegate
{
EmailAddressChooserTask chooser = new EmailAddressChooserTask();
chooser.Completed += new EventHandler<EmailResult>((sender, e) =>
{
if (e.TaskResult == TaskResult.OK && e.Email != null && e.Email != "")
pi.SetValue(task, e.Email, null);
});
//.........这里部分代码省略.........
示例8: App
/// <summary>
/// Constructor for the Application object.
/// </summary>
public App()
{
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
// Standard XAML initialization
InitializeComponent();
// Phone-specific initialization
InitializePhoneApplication();
// Language display initialization
InitializeLanguage();
// Show graphics profiling information while debugging.
if (Debugger.IsAttached)
{
// Display the current frame rate counters.
Application.Current.Host.Settings.EnableFrameRateCounter = true;
// Show the areas of the app that are being redrawn in each frame.
//Application.Current.Host.Settings.EnableRedrawRegions = true;
// Enable non-production analysis visualization mode,
// which shows areas of a page that are handed off to GPU with a colored overlay.
//Application.Current.Host.Settings.EnableCacheVisualization = true;
// Prevent the screen from turning off while under the debugger by disabling
// the application's idle detection.
// Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
// and consume battery power when the user is not using the phone.
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("app_code"))
{
string appCode = Convert.ToString(settings["app_code"]);
string appUniq = Convert.ToString(settings["app_uniq"]);
string pwd = Convert.ToString(settings["app_pwd"]);
App.helper = new CBHelper(appCode, appUniq);
App.helper.SetPassword(pwd.ToLower());
}
// enable geo-location for the data APIs.
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.PositionChanged += delegate(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
if (watcher != null)
{
if (App.helper != null)
{
// once we have a location we set the variable in the helper class and we stop looking
App.helper.CurrentLocation = e.Position;
watcher.Stop();
watcher.Dispose();
watcher = null;
}
}
};
watcher.Start();
this.Notifications_Start();
}
示例9: GetUserPostion
public void GetUserPostion()
{
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>((s, e) =>
{
latitude = e.Position.Location.Latitude;
longitude = e.Position.Location.Longitude;
watcher.Stop();
this.GetBestServer();
});
watcher.Start();
}
示例10: OnLastKnownLocation
private void OnLastKnownLocation(PushMessage msg)
{
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
switch (watcher.Status)
{
case GeoPositionStatus.Disabled:
RLog.N(this, "Location", "Geolocation status:" + watcher.Status.ToString());
break;
default:
{
watcher.MovementThreshold = 20;
watcher.PositionChanged += (o, args) =>
{
RLog.N(this, "Location", GetLocationSring(args.Position.Location));
watcher.Stop();
};
watcher.Start();
}
break;
}
}
示例11: RenderEditItemField
private void RenderEditItemField(Item item, Field field)
{
// skip rendering a hidden field
if (field.DisplayType == DisplayTypes.Hidden)
return;
PropertyInfo pi = null;
object currentValue = null;
object container = null;
// get the current field value.
// the value can either be in a strongly-typed property on the item (e.g. Name),
// or in one of the FieldValues
try
{
// get the strongly typed property
pi = item.GetType().GetProperty(field.Name);
if (pi != null)
{
// store current item's value for this field
currentValue = pi.GetValue(item, null);
// set the container - this will be the object that will be passed
// to pi.SetValue() below to poke new values into
container = itemCopy;
}
}
catch (Exception)
{
// an exception indicates this isn't a strongly typed property on the Item
// this is NOT an error condition
}
// if couldn't find a strongly typed property, this property is stored as a
// FieldValue on the item
if (pi == null)
{
// get current item's value for this field, or create a new FieldValue
// if one doesn't already exist
FieldValue fieldValue = item.GetFieldValue(field.ID, true);
currentValue = fieldValue.Value;
// get the value property of the current fieldvalue (this should never fail)
pi = fieldValue.GetType().GetProperty("Value");
if (pi == null)
return;
// set the container - this will be the object that will be passed
// to pi.SetValue() below to poke new values into
container = fieldValue;
}
ListBoxItem listBoxItem = new ListBoxItem();
StackPanel EditStackPanel = new StackPanel();
listBoxItem.Content = EditStackPanel;
EditStackPanel.Children.Add(
new TextBlock()
{
Text = field.DisplayName,
Style = (Style)App.Current.Resources["PhoneTextNormalStyle"]
});
// create a textbox (will be used by the majority of field types)
double minWidth = App.Current.RootVisual.RenderSize.Width;
if ((int)minWidth == 0)
minWidth = ((this.Orientation & PageOrientation.Portrait) == PageOrientation.Portrait) ? 480.0 : 800.0;
TextBox tb = new TextBox() { DataContext = container, MinWidth = minWidth, IsTabStop = true };
tb.SetBinding(TextBox.TextProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
bool notMatched = false;
// render the right control based on the DisplayType
switch (field.DisplayType)
{
case DisplayTypes.Text:
tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
tb.TabIndex = tabIndex++;
tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
EditStackPanel.Children.Add(tb);
break;
case DisplayTypes.TextArea:
tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
tb.AcceptsReturn = true;
tb.TextWrapping = TextWrapping.Wrap;
tb.Height = 150;
tb.TabIndex = tabIndex++;
tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
EditStackPanel.Children.Add(tb);
break;
case DisplayTypes.Phone:
tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.TelephoneNumber } } };
tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
tb.TabIndex = tabIndex++;
tb.MinWidth -= 64;
tb.MaxWidth = tb.MinWidth;
StackPanel innerPanel = RenderImageButtonPanel(tb);
ImageButton imageButton = (ImageButton)innerPanel.Children[1];
imageButton.Click += new RoutedEventHandler(delegate
{
//.........这里部分代码省略.........
示例12: write
public bool write(int radiusMeters, string title, string msg, bool showLocation)
{
GeoCoordinateWatcher getPosition = new GeoCoordinateWatcher();
getPosition.TryStart(false, TimeSpan.FromMilliseconds(1000));
float lat = (float)getPosition.Position.Location.Latitude;
float lon = (float)getPosition.Position.Location.Longitude;
getPosition.Stop();
getPosition.Dispose();
latLon position = new latLon(lat, lon);
double r = (double)radiusMeters / (double)R;
int gridI = -1;
double latRad = mathPlus.DegreeToRadian((double)position.getLat());
float latStart = (float)mathPlus.RadianToDegree(latRad - r);
float latEnd = (float)mathPlus.RadianToDegree(latRad + r);
double lonRad = mathPlus.DegreeToRadian((double)position.getLon());
double tLon = Math.Asin(Math.Sin(r) / Math.Cos(latRad));
float lonStart = (float)mathPlus.RadianToDegree(lonRad - tLon);
float lonEnd = (float)mathPlus.RadianToDegree(lonRad + tLon);
latLon nw = new latLon(latStart, lonStart);
latLon ne = new latLon(latStart, lonEnd);
latLon se = new latLon(latEnd, lonEnd);
latLon sw = new latLon(latEnd, lonStart);
string[] nwGrid = nw.getGrids();
string[] neGrid = ne.getGrids();
string[] seGrid = se.getGrids();
string[] swGrid = sw.getGrids();
for (int i = 0; i < position.getGridCount(); i++)
{
if (nwGrid[i] == neGrid[i]
&& nwGrid[i] == seGrid[i]
&& nwGrid[i] == swGrid[i])
{
gridI = i;
break;
}
}
if (gridI < 0) return false;
StringBuilder output = new StringBuilder("");
DB db = new DB();
db.setOutput(output);
db.write( myUser.getUserID()
, nwGrid[gridI]
, position.getLat()
, position.getLon()
, position.getSysLat()
, position.getSysLon()
, nw.getSysLat()
, sw.getSysLat()
, nw.getSysLon()
, ne.getSysLon()
, radiusMeters
, showLocation
, title
, msg
);
statusMsg status = JsonConvert.DeserializeObject<statusMsg>(output.ToString());
return true;
}
示例13: read
public readData read()
{
GeoCoordinateWatcher getPosition = new GeoCoordinateWatcher();
getPosition.TryStart(false, TimeSpan.FromMilliseconds(1000));
float lat = (float)getPosition.Position.Location.Latitude;
float lon = (float)getPosition.Position.Location.Longitude;
getPosition.Stop();
getPosition.Dispose();
latLon position = new latLon(lat, lon);
StringBuilder htmlOutput = new StringBuilder("");
DB db = new DB();
db.setOutput(htmlOutput);
db.read(position);
readData output = JsonConvert.DeserializeObject<readData>(htmlOutput.ToString());
return output;
}