• WP7备注(10)(Accelerometer+GeoCoordinateWatcher+Map Service)


    Accelerometer基本设置:

    Library:+Microsoft.Devices.Sensors

    WMAppManifest.xml:+<Capability Name="ID_CAP_SENSORS" />

    Accelerometer(Silverlight):

    Accelerometer acc = new Accelerometer();
    acc.ReadingChanged += OnAccelerometerReadingChanged;
    acc.Start();
    
    void OnAccelerometerReadingChanged(object sender, AccelerometerReadingEventArgs
    args)
    {}

    Accelerometer(XNA):

    Vector3 accelerometerVector;
    object accelerometerVectorLock = new object();
    Accelerometer accelerometer = new Accelerometer();
    accelerometer.ReadingChanged += OnAccelerometerReadingChanged;
    
    void OnAccelerometerReadingChanged(object sender, AccelerometerReadingEventArgs
    args)
    {
    lock (accelerometerVectorLock)
    {
    accelerometerVector = new Vector3((float)args.X, (float)args.Y,
    (float)args.Z);
    }

    GeoCoordinateWatcher基本设置:

    Library:+System.Device.Location

    WMAppManifest.xml:+<Capability Name="ID_CAP_LOCATION" />

    GeoCoordinateWatcher:

    GeoCoordinateWatcher geoWatcher = new GeoCoordinateWatcher();
    geoWatcher.PositionChanged += OnGeoWatcherPositionChanged;
    geoWatcher.Start();
    
    void OnGeoWatcherPositionChanged(object sender,
    GeoPositionChangedEventArgs<GeoCoordinate> args)
    {
    text = String.Format("Latitude: {0:F3}\r\n" +
    "Longitude: {1:F3}\r\n" +
    "Altitude: {2}\r\n\r\n" +
    "{3}",
    args.Position.Location.Latitude,
    args.Position.Location.Longitude,
    args.Position.Location.Altitude,
    args.Position.Timestamp);
    }

    Map Service:

    GeoCoordinateWatcher geoWatcher = new GeoCoordinateWatcher();
    TerraServiceSoapClient proxy = new TerraServiceSoapClient();
    
    proxy.GetAreaFromPtCompleted += OnProxyGetAreaFromPtCompleted;
    proxy.GetTileCompleted += OnProxyGetTileCompleted;
    statusText.Text = "Obtaining geographic location...";
    geoWatcher.PositionChanged += OnGeoWatcherPositionChanged;
    geoWatcher.Start();
    
    void OnGeoWatcherPositionChanged(object sender,
    GeoPositionChangedEventArgs<GeoCoordinate> args)
    {
    // Turn off GeoWatcher
    geoWatcher.PositionChanged -= OnGeoWatcherPositionChanged;
    geoWatcher.Stop();
    // Set coordinates to title text
    GeoCoordinate coord = args.Position.Location;
    ApplicationTitle.Text += ": " + String.Format("{0:F2}°{1} {2:F2}°{3}",
    Math.Abs(coord.Latitude),
    coord.Latitude > 0 ? 'N' : 'S',
    Math.Abs(coord.Longitude),
    coord.Longitude > 0 ? 'E' : 'W');
    // Query proxy for AreaBoundingBox
    LonLatPt center = new LonLatPt();
    center.Lon = args.Position.Location.Longitude;
    center.Lat = args.Position.Location.Latitude;
    statusText.Text = "Accessing Microsoft Research Maps Service...";
    proxy.GetAreaFromPtAsync(center, 1, Scale.Scale16m,
    (int)ContentPanel.ActualWidth,
    (int)ContentPanel.ActualHeight);
    }
    
    void OnProxyGetAreaFromPtCompleted(object sender, GetAreaFromPtCompletedEventArgs
    args)
    {
    if (args.Error != null)
    {
    statusText.Text = args.Error.Message;
    return;
    }
    statusText.Text = "Getting map tiles...";
    AreaBoundingBox box = args.Result;
    int xBeg = box.NorthWest.TileMeta.Id.X;
    int yBeg = box.NorthWest.TileMeta.Id.Y;
    int xEnd = box.NorthEast.TileMeta.Id.X;
    int yEnd = box.SouthWest.TileMeta.Id.Y;
    // Loop through the tiles
    for (int x = xBeg; x <= xEnd; x++)
    for (int y = yBeg; y >= yEnd; y--)
    {
    // Create Image object to display tile
    Image img = new Image();
    img.Stretch = Stretch.None;
    img.HorizontalAlignment = HorizontalAlignment.Left;
    img.VerticalAlignment = VerticalAlignment.Top;
    img.Margin = new Thickness((x - xBeg) * 200 -
    box.NorthWest.Offset.XOffset,
    (yBeg - y) * 200 -
    box.NorthWest.Offset.YOffset,
    0, 0);
    // Insert after TextBlock but before Image with logo
    ContentPanel.Children.Insert(1, img);
    // Define the tile ID
    TileId tileId = box.NorthWest.TileMeta.Id;
    tileId.X = x;
    tileId.Y = y;
    // Call proxy to get the tile (Notice that Image is user object)
    proxy.GetTileAsync(tileId, img);
    }
    }
    
    void OnProxyGetTileCompleted(object sender, GetTileCompletedEventArgs args)
    {
    if (args.Error != null)
    {
    return;
    }
    Image img = args.UserState as Image;
    BitmapImage bmp = new BitmapImage();
    bmp.SetSource(new MemoryStream(args.Result));
    img.Source = bmp;
    }
  • 相关阅读:
    160309_Qt Essentials
    160309_Qt Reference Documentation
    160308_Signals & Slots
    160308_Helloworld_Gui Application
    网络爬虫(14)-动态页面爬取
    数据分析(6)-Pandas日期数据处理
    mysql基础(2)-excel功能在excel中如何实现?
    数据分析(5)-数据可视化常用图表类型和使用场景
    财经数据(6)-Python多进程爬虫东方财富个股盘口异动数据
    财经数据(5)-开盘啦股票标签数据爬虫
  • 原文地址:https://www.cnblogs.com/otomii/p/2030101.html
Copyright © 2020-2023  润新知