Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public string toUtmString(double lon, double lat, double elev)
        {
            string ret = "";            // UTM = 11S 0433603E 3778359N

            LonLatPt lonlat = new LonLatPt();

            lonlat.Lat = lat;
            lonlat.Lon = lon;

            UtmPt utmpt = Projection.LonLatPtToUtmNad83Pt(lonlat);

            ret = "" + utmpt.Zone + "S " + string.Format("{0:d07}", (int)Math.Round(utmpt.X)) + "E " + string.Format("{0:d07}", (int)Math.Round(utmpt.Y)) + "N";

            return(ret);
        }
Esempio n. 3
0
        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);
        }
        /// <summary> The main entry point for the application. </summary>
        static void Main(string[] args)
        {
            // Create the GPS point from your location services data
            LonLatPt location = new LonLatPt();

            // Modify Lat and Lon based on your needs
            // This example uses the GPS Coordinates for "Eau Claire, Wisconsin, United States"
            location.Lat = 44.811349;
            location.Lon = -91.498494;

            // Create a new TerraService object
            TerraService ts = new TerraService();

            // Output the nearest location from the TerraService
            Console.WriteLine(ts.ConvertLonLatPtToNearestPlace(location));

            // For console app to stay open/close easily
            Console.WriteLine("Press any key to close window...");
            Console.ReadKey();

            // Lastly, appreciate the Microsoft folks that made this available for free
            // They are all interesting individuals but you should read about Jim Gray via Wikipedia to
            // understand some history behind this cool web service.
        }
        public static void GetCityData(int addressID)
        {
            try
            {
                using (SqlConnection cn = new SqlConnection("context connection=true"))
                {
                    cn.Open();
                    string     selectQuery = @"SELECT a.City, s.Name As State, c.Name As Country
                                      FROM Person.Address a
                                      INNER JOIN Person.StateProvince s
                                      ON a.StateProvinceID = s.StateProvinceID
                                         INNER JOIN Person.CountryRegion c
                                         ON s.CountryRegionCode = c.CountryRegionCode
                                      WHERE a.AddressID = @addressID";
                    SqlCommand selectCmd   = new SqlCommand(selectQuery, cn);
                    selectCmd.Parameters.AddWithValue("@addressID", addressID);
                    SqlDataReader reader = selectCmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        reader.Read();
                        string city    = (string)reader[0];
                        string state   = (string)reader[1];
                        string country = (string)reader[2];
                        reader.Close();
                        string placeName = city + ", " + state + ", " + country;

                        string       insertQuery    = "INSERT INTO Person.CityDetails VALUES (@addressID, @name, @longitude, @latitude, @population, @image)";
                        SqlCommand   insertCmd      = new SqlCommand(insertQuery, cn);
                        SqlParameter addressIDParam = new SqlParameter("@addressID", SqlDbType.Int);
                        SqlParameter nameParam      = new SqlParameter("@name", SqlDbType.NVarChar, 256);
                        SqlParameter longParam      = new SqlParameter("@longitude", SqlDbType.Float);
                        SqlParameter latParam       = new SqlParameter("@latitude", SqlDbType.Float);
                        SqlParameter popParam       = new SqlParameter("@population", SqlDbType.Int);
                        SqlParameter imgParam       = new SqlParameter("@image", SqlDbType.Image);
                        insertCmd.Parameters.AddRange(new SqlParameter[] { addressIDParam, nameParam, longParam, latParam, popParam, imgParam });
                        addressIDParam.Value = addressID;

                        TerraService terraService = new TerraService();
                        PlaceFacts[] places       = terraService.GetPlaceList(placeName, 100, false);
                        foreach (PlaceFacts facts in places)
                        {
                            LonLatPt coords   = facts.Center;
                            TileMeta metadata = terraService.GetTileMetaFromLonLatPt(coords, 1, Scale.Scale8m);
                            byte[]   image    = terraService.GetTile(metadata.Id);
                            nameParam.Value = facts.Place.City;
                            longParam.Value = coords.Lon;
                            latParam.Value  = coords.Lat;
                            popParam.Value  = facts.Population;
                            imgParam.Value  = image;
                            try
                            {
                                insertCmd.ExecuteNonQuery();
                            }
                            catch (Exception e)
                            {
                                SqlContext.Pipe.Send("Cannot insert row for place " + facts.Place.City);
                                SqlContext.Pipe.Send(e.Message);
                            }
                        }
                        cn.Close();

                        SqlContext.Pipe.Send("Command executed successfully.");
                        terraService.Dispose();
                    }
                    else
                    {
                        reader.Close();
                        cn.Close();
                        SqlContext.Pipe.Send("No addresses in the database match the specified ID.");
                    }
                }
            }
            catch (Exception e)
            {
                SqlContext.Pipe.Send("An error occurred executing the GetCityData stored procedure:");
                SqlContext.Pipe.Send(e.Message);
            }
        }