void LocationChanged(object sender, LocationEventArgs e) { activity.RunOnUiThread(delegate { LatLng ll = RandomLatLng(); MarkerOptions opts = new MarkerOptions(); opts.SetPosition(RandomLatLng()); opts.SetTitle(ll.Latitude + ", " + ll.Longitude); if (fish) { opts.SetSnippet("Fish caught"); } else { opts.SetSnippet("No fish"); } m.Remove(); m = googleMap.AddMarker(opts); if (infoVisible) { m.ShowInfoWindow(); } //googleMap.MoveCamera (CameraUpdateFactory.NewLatLng (new LatLng (e.Lat, e.Lon))); }); }
static void ReadNextBytes(int offset) { byte [] buffer = new byte [bufSize]; var result = Socket.InputStream.BeginRead(buffer, offset, bufSize, delegate { string raw = string.Join(", ", buffer); string ascii = encoder.GetString(buffer); WriteLine("RAW:\t" + raw); WriteLine("ASCII:\t" + ascii); WriteLine("----"); if (ascii.Contains("STATE") && ascii.Contains("0")) { NoFish?.Invoke(null, EventArgs.Empty); } else if (ascii.Contains("STATE") && ascii.Contains("1")) { YesFish?.Invoke(null, EventArgs.Empty); } //$GPGLL,5821.95899,N,02641.45598,e,085306.00,a,a * 6f if (ascii.Contains("GPGLL")) { string [] pieces = ascii.Split(','); double lat; double lon; try { double.TryParse(pieces [1], out lat); double.TryParse(pieces [3], out lon); if (lat > 0 && lon > 0) { LocationEventArgs args = new LocationEventArgs(); args.Lat = lat / 100; args.Lon = lon / 100; LocationChanged?.Invoke(null, args); } } catch { } } if (!reading) { return; } if (buffer [buffer.Length - 1] == 0) { ReadNextBytes(0); } else { ReadNextBytes(bufSize); } }, null); }