Esempio n. 1
0
 protected virtual void OnPositionChanged(PositionEventArgs e)
 {
     if (e.status == PositionEventArgs.PositionStatus.Valid)
         LastPos = e.position;
     else
         LastPos = null;
     if (PositionChanged != null)
         PositionChanged(this, e);
 }
Esempio n. 2
0
 public void StartGPS()
 {
     position = null;
     if (ClientSettings.UseGPS)
     {
         gps.LocationChanged += new PockeTwit.GPS.LocationChangedEventHandler(gps_LocationChanged);
         if (!gps.Opened)
         {
             gps.Open();
         }
     }
     if (ril != null)
     {
         ril.PositionChanged += new EventHandler<PositionEventArgs>(RILPositionChanged);
         ril.Enabled = true;
     }
 }
Esempio n. 3
0
 private void PositionChanged(object sender, PositionEventArgs pe)
 {
     if (LocationReady != null)
     {
         if (pe.status == PositionEventArgs.PositionStatus.Valid)
         {
             position = pe.position;
             LocationReady(position, sender== ril ? LocationSource.RIL : LocationSource.GPS);
         }
     }
 }
Esempio n. 4
0
        void gps_LocationChanged(object sender, PockeTwit.GPS.LocationChangedEventArgs args)
        {
            PositionEventArgs.PositionStatus stat = PositionEventArgs.PositionStatus.Invalid;
            PockeTwit.Position.GeoCoord le = new PockeTwit.Position.GeoCoord(0, 0);

            if (gps.Opened)
            {
                try
                {
                    if (args.Position == null) { stat = PositionEventArgs.PositionStatus.Invalid; }
                    if (args.Position.LatitudeValid && args.Position.LongitudeValid)
                    {
                        if (!Double.IsNaN(args.Position.Longitude) && !Double.IsNaN(args.Position.Latitude))
                        {
                            le = new PockeTwit.Position.GeoCoord(args.Position.Latitude, args.Position.Longitude);
                            stat = PositionEventArgs.PositionStatus.Valid;
                        }
                    }
                }
                catch (DivideByZeroException)
                {
                    stat = PositionEventArgs.PositionStatus.Error;
                }

            }
            // once we know where we are precisely, stop looking
            if (stat == PositionEventArgs.PositionStatus.Valid && ril != null)
                ril.Enabled = false; // turn RIL off immediately
            PositionChanged(sender, new PositionEventArgs(stat, le, DateTime.Now));
            if (stat == PositionEventArgs.PositionStatus.Valid)
                StopGPS(); // and stop GPS
        }
Esempio n. 5
0
        public List<Place> GetNearbyPlaces(GeoCoord position)
        {
            List<Place> twitPlaces = new List<Place>();
            Dictionary<string, PlaceType> placeTypes = new Dictionary<string,PlaceType>();
            placeTypes.Add("poi", PlaceType.Poi);
            placeTypes.Add("neighborhood", PlaceType.Neighbourhood);
            placeTypes.Add("city", PlaceType.City);
            placeTypes.Add("admin", PlaceType.Administrative);
            placeTypes.Add("country", PlaceType.Country);

            string url = string.Format(TwitterNewBaseUrlFormat, GetObjectTypeString(ObjectType.Geo), GetActionTypeString(ActionType.Search),  GetFormatTypeString(OutputFormatType.JSON));
            url += string.Format("?lat={0}&long={1}&granularity=poi", position.Lat.ToString(CultureInfo.InvariantCulture), position.Lon.ToString(CultureInfo.InvariantCulture));
            string jsonresp = ExecuteGetCommand(url);

            Hashtable jsonResponse = PockeTwit.JSON.JsonDecode(jsonresp) as Hashtable;
            if (jsonResponse != null)
            {
                Hashtable result = jsonResponse["result"] as Hashtable;
                if (result != null)
                {
                    ArrayList places = result["places"] as ArrayList;
                    if (places != null)
                    {
                        foreach (Hashtable place in places)
                        {
                            twitPlaces.Add(
                                new TwitterPlace
                                {
                                    TwitterPlaceID = place["id"].ToString(),
                                    DisplayName = place["full_name"].ToString(),
                                    Type = placeTypes[place["place_type"].ToString()],
                                    Position = position // until we do bounding boxes
                                }
                            );
                        }
                    }
                }
            }
            return twitPlaces;
        }
Esempio n. 6
0
 void l_LocationReady(GeoCoord Location, LocationManager.LocationSource Source)
 {
     // We're in a separate thread, probably - grab the places from Twitter
     if (Location != null)
     {
         if (GPSLocation != null && Source == LocationManager.LocationSource.RIL)
             return; // if we've got a location and RIL gives another one, ignore it
         Twitter Conn = Servers.CreateConnection(AccountToSet);
         if (Conn is PlaceAPI)
         {
             PlaceAPI PlaceSearch = Conn as PlaceAPI;
             places = PlaceSearch.GetNearbyPlaces(Location);
         }
         DoLocationReady(Location, Source);
     }
 }
Esempio n. 7
0
 void DoLocationReady(GeoCoord Location, LocationManager.LocationSource Source)
 {
     try
     {
         if (InvokeRequired)
         {
             LocationManager.delLocationReady d = new LocationManager.delLocationReady(DoLocationReady);
             BeginInvoke(d, Location, Source);
         }
         else
         {
             GPSLocation = Location;
             lblGPS.Text = PockeTwit.Localization.XmlBasedResourceManager.GetString("Location Found");
             lblGPS.Text += " (" + Source.ToString() + ")";
             if (DetectDevice.DeviceType == DeviceType.Standard)
             {
                 // just enable the menuItem
                 if (null != menuGPSInsert)
                 {
                     menuGPSInsert.Enabled = true;
                 }
             }
             else
             {
                 picInsertGPSLink.Visible = true;
             }
             Place selP = null; // currently selected place, if any
             if (cmbPlaces.SelectedItem is Place)
             {
                 selP = cmbPlaces.SelectedItem as Place;
             }
             cmbPlaces.Items.Clear();
             cmbPlaces.Visible = true;
             cmbPlaces.Items.Add(GPSLocation);
             cmbPlaces.SelectedIndex = 0;
             if (places != null)
             {
                 foreach (Place p in places)
                     cmbPlaces.Items.Add(p);
             }
             foreach (object item in cmbPlaces.Items)
             {
                 if (item is Place)
                 {
                     Place p = item as Place;
                     if (p.Equals(selP))
                     {
                         cmbPlaces.SelectedItem = p;
                         break;
                     }
                 }
             }
             if (cmbPlaces.SelectedItem is GeoCoord && selP != null) // not selected a place
             {
                 cmbPlaces.Items.Add(selP);
                 cmbPlaces.SelectedItem = selP;
             }
         }
     }
     catch (ObjectDisposedException)
     {
     }
 }
Esempio n. 8
0
 private void StartLocating()
 {
     //StartAnimation
     cmbPlaces.Visible = false;
     LocationFinder.StopGPS(); // in case it's running
     LocationFinder.StartGPS();
     lblGPS.Text = PockeTwit.Localization.XmlBasedResourceManager.GetString("Seeking GPS");
     GPSLocation = null;
     //pictureLocation.Visible = false;
     //lblGPS.Visible = true;
 }
Esempio n. 9
0
 public PositionEventArgs(PositionStatus status, GeoCoord position, DateTime time)
 {
     this.status = status;
     this.position = position;
     this.time = time;
 }
Esempio n. 10
0
 void Locator_LocationReady(GeoCoord Location, LocationManager.LocationSource Source)
 {
     GPSLocation = Location;
     GPSLocked();
 }