private void NearbyBusStop_ItemClick(object sender, ItemClickEventArgs e) { BusStopLineDirection clickedMenuItem = (BusStopLineDirection)e.ClickedItem; if (clickedMenuItem != null) { BusStopAll stopInfo = clickedMenuItem.BusStopInfo; if (stopInfo != null) { Debug.WriteLine(stopInfo.BusStopName); Frame root = Window.Current.Content as Frame; root.Navigate(typeof(StopDetail), stopInfo); } } }
async private Task GetNearbyBusStop() { var access = await Geolocator.RequestAccessAsync(); switch (access) { case GeolocationAccessStatus.Unspecified: // Geoposition not opened return; case GeolocationAccessStatus.Allowed: isNearbyLoading = true; nearbyRing.Visibility = Visibility.Visible; // All is well var gt = new Geolocator(); var position = await gt.GetGeopositionAsync(); // position.Coordinate.Latitude; // Descraped // map.Center = position.Coordinate.Point; BasicGeoposition snPosition = new BasicGeoposition { Latitude = 49.40347, Longitude = 2.8072 }; // Standard test coordinate if (isMapElementsLayersAPIPresent) { map.Center = position.Coordinate.Point; map.ZoomLevel = 17; } //Create an HTTP client object HttpClient httpClient = new HttpClient(); //Add a user-agent header to the GET request. var headers = httpClient.DefaultRequestHeaders; Uri requestUri = new Uri("http://66.42.32.248/wechat/api/stop_nearby.php"); List <KeyValuePair <string, string> > formData = new List <KeyValuePair <string, string> >(); formData.Add(new KeyValuePair <string, string>("lat", position.Coordinate.Point.Position.Latitude + "")); formData.Add(new KeyValuePair <string, string>("lon", position.Coordinate.Point.Position.Longitude + "")); formData.Add(new KeyValuePair <string, string>("level", "2")); HttpFormUrlEncodedContent content = new HttpFormUrlEncodedContent(formData); try { //Send the GET request asynchronously and retrieve the response as a string. HttpResponseMessage httpResponse = new HttpResponseMessage(); string httpResponseBody = ""; // Send the POST request httpResponse = await httpClient.PostAsync(requestUri, content); httpResponse.EnsureSuccessStatusCode(); httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); Debug.WriteLine(httpResponseBody); JsonObject jsonObject = JsonObject.Parse(httpResponseBody); // Parse state // Parse datas JsonArray data = jsonObject["data"].GetArray(); var BusStopMarkers = new List <MapElement>(); // Create a list // Clear Nearby Lines NearbyLines.Clear(); for (uint i = 0; i < data.Count; i++) { // Parse stop JsonObject stopObject = data.GetObjectAt(i); if (stopObject == null) { continue; } string stopName = stopObject["stop"].GetString(); JsonObject positionObject = stopObject["pos"].GetObject(); if (positionObject == null) { continue; } double longitude = double.Parse(positionObject["lon"].GetString()), latitude = double.Parse(positionObject["lat"].GetString()); // Create bus stop - line list BusStopLineDirection busStopLineDirection = new BusStopLineDirection(); busStopLineDirection.StopName = stopName; JsonArray busStopLineDirectionList = stopObject["lines"].GetArray(); if (busStopLineDirectionList != null) { for (int j = 0; j < busStopLineDirectionList.Count; j++) { JsonObject busStopLineDirectionObject = busStopLineDirectionList[j].GetObject(); if (busStopLineDirectionObject != null) { string line = busStopLineDirectionObject["line"].GetString(); string direction = busStopLineDirectionObject["direction"].GetString(); if (line == null || direction == null) { continue; } string directionName = Line.NAME[(int.Parse(line) - 1) * 2 + (int.Parse(direction) - 1)]; busStopLineDirection.LineDirection.Add(new BusLineDirection() { Line = line, DirectionName = directionName }); } } if (busStopLineDirection.LineDirection.Count > 0) { string stopId = stopObject["id"].GetString(); if (stopId != null) { busStopLineDirection.BusStopInfo = new BusStopAll() { BusStopName = stopName, Lat = latitude, Lon = longitude, BusStopId = int.Parse(stopId) }; } NearbyLines.Add(busStopLineDirection); } } // Create and add bus stop marker BasicGeoposition stopPosition = new BasicGeoposition { Latitude = latitude, Longitude = longitude }; BusStopMarkers.Add(new MapIcon { Location = new Geopoint(stopPosition), NormalizedAnchorPoint = new Point(0.5, 1.0), ZIndex = 0, Title = stopName } ); } if (isMapElementsLayersAPIPresent) { layer.MapElements = BusStopMarkers; } } catch (Exception ex) { // Refresh error } isNearbyLoading = false; nearbyRing.Visibility = Visibility.Collapsed; break; case GeolocationAccessStatus.Denied: // Not allowed await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings://privacy/location")); return; default: break; } }