コード例 #1
0
		public async Task<Feature> AddToilet(string city, Feature toilet)
		{
			Feature userRet = null;

			using (var client = new HttpClient())
			{
				client.BaseAddress = new Uri(BASE_URL_PATH);
				client.DefaultRequestHeaders.Accept.Clear();
				client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

				NameValueCollection queryParams = new NameValueCollection()
				{
					{ "apiKey", API_KEY },
				};

				Uri requestUri = new Uri(
					string.Concat(
						BASE_URL_PATH,
						"/databases/znajdzwcdb/collections/",
						city,
						ExtensionMethods.ToQueryString(queryParams)
					)
				);

				var jsonPayload = JsonConvert.SerializeObject(toilet, Formatting.Indented);

				var stringContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json");

				HttpResponseMessage response = await client.PostAsync(
					requestUri,
					stringContent
				);

				response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
				response.EnsureSuccessStatusCode();

				if (response.IsSuccessStatusCode)
				{
					Task<string> con = response.Content.ReadAsStringAsync();

					userRet = JsonConvert.DeserializeObject<Feature>(con.Result);
				}
			}

			return userRet;
		}
コード例 #2
0
		private void SetUpMapIfNeeded() 
		{
			if(null != _googleMap) 
				return;

			CameraPosition.Builder builder = CameraPosition.InvokeBuilder ();

			LatLng location = new LatLng (Convert.ToDouble(_latitude), Convert.ToDouble(_longitude));
			builder.Target (location);
			builder.Zoom (15);

			CameraPosition cameraPosition = builder.Build ();
			CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition (cameraPosition);

			var mapReadyCallback = new OnMapReadyClass();
			mapReadyCallback.MapReady += (sender, e) =>
			{
				_googleMap = ((OnMapReadyClass)sender).Map; 
				_googleMap.MapType = GoogleMap.MapTypeNormal;
				_googleMap.AnimateCamera(cameraUpdate);

				List<Feature> data = new List<Feature>();

				List<double> coord = new List<double> ();
				coord.Add (Convert.ToDouble(_longitude));
				coord.Add (Convert.ToDouble(_latitude));

				_toilet = new Feature () 
				{
					type = "Feature",
					geometry = new Geometry()
					{
						coordinates = coord,
						type = "Point"
					},
					properties = new Properties()
					{
						ranking = "0",
						id = "0",
						name = _name,
						icon = "znajdz_wc_logo_free_marker.png",
						isFree = _isFree,
						comment = _comment,
						photo = "",
						openHours = "",
						isVerified = false,
					}
				};

				data.Add(_toilet);

				GoogleMapHelpers.PlaceMarkersOnTheMap(data, _googleMap);

				_googleMap.SetInfoWindowAdapter(new CustomMarkerPopupAdapter(LayoutInflater));
			};

			try {
				_myMapFragment.GetMapAsync(mapReadyCallback); 

			} catch (NullReferenceException ex) {
				Console.WriteLine(ex.Source);
			}
		}
コード例 #3
0
		private async void _sendNewToiletButton_Click (object sender, System.EventArgs e)
		{
			ConnectivityManager connectivityManager = (ConnectivityManager) GetSystemService(ConnectivityService);

			NetworkInfo activeConnection = connectivityManager.ActiveNetworkInfo;
			bool isOnline = (activeConnection != null) && activeConnection.IsConnected;

			if (isOnline) 
			{
				_name = _edittext.Text;

				List<double> coord = new List<double> ();
				coord.Add (Convert.ToDouble(_longitude));
				coord.Add (Convert.ToDouble(_latitude));

				_toilet = new Feature () 
				{
					type = "Feature",
					geometry = new Geometry()
					{
						coordinates = coord,
						type = "Point"
					},
					properties = new Properties()
					{
						ranking = "0",
						id = "0",
						name = _name,
						icon = "znajdz_wc_logo_free_marker.png",
						isFree = _isFree,
						comment = _comment,
						photo = "",
						openHours = "",
						isVerified = false,
					}
				};

				try {
					await _toiletsRepository.AddToilet(_selectedCity, _toilet);

				} catch (ArgumentNullException an) {
					Toast.MakeText (this, an.Message, ToastLength.Long).Show ();
					this.Finish ();
				}

				Toast.MakeText (this, "Dziękujemy", ToastLength.Long).Show ();

				this.Finish ();
			} else 
			{
				Toast.MakeText (this, "Brak dostępu do Internetu", ToastLength.Long).Show ();

				this.Finish ();
			}
		}