public static void TestBoundingBox() { GeoBoundingBox bb = GeoBoundingBox.FromDistance(44.168278M, 4.445944M, 50); // https://www.openstreetmap.org/api/0.6/map?bbox=4.4453171181025916513184263020,44.167828339818137730558940096,4.4465708818974083486815736980,44.168727660181862269441059904 XML.OsmBoundingBoxXml xml = XML.OsmBoundingBoxXml.FromUrl(bb.Url); System.Console.WriteLine(xml); }
/// <summary> /// Forms and sends a geocoding request to retrieve location infromation for the provided address query. /// The specified GeoBoundingBox helps improve the result's relevance. /// </summary> public async static Task <MapLocationFinderResult> FindLocations( string query, GeoBoundingBox referenceBoundingBox, MapLocationOptions mapLocationOptions = null) { var url = BuildUrl($"q={query}", mapLocationOptions); url += $"&umv={referenceBoundingBox.BottomLeft.LatitudeInDegrees},{referenceBoundingBox.BottomLeft.LongitudeInDegrees},{referenceBoundingBox.TopRight.LatitudeInDegrees},{referenceBoundingBox.TopRight.LongitudeInDegrees}"; return(await Request(url)); }
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { var s = value as string; if (s == null) { return(base.ConvertFrom(context, culture, value)); } GeoBoundingBox bbox = s; return(bbox); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { GeoBoundingBox bbox = value as GeoBoundingBox ?? value as string; if (bbox != null) { writer.WriteStartObject(); writer.WritePropertyName(TopLeftPropertyName); serializer.Serialize(writer, bbox.TopLeft); writer.WritePropertyName(BottomRightPropertyName); serializer.Serialize(writer, bbox.BottomRight); writer.WriteEndObject(); } }
/// <summary> /// Forms and sends a geocoding request to retrieve location infromation for the provided address query. /// The specified GeoBoundingBox helps improve the result's relevance. /// </summary> public async static Task <MapLocationFinderResult> FindLocations( string query, GeoBoundingBox referenceBoundingBox, MapLocationOptions mapLocationOptions = null) { var mapLocationOptionsForRequest = mapLocationOptions ?? new MapLocationOptions(); if (!ValidateMapSession(mapLocationOptionsForRequest)) { return(new MapLocationFinderResult(MapLocationFinderStatus.InvalidCredentials)); } var url = await BuildUrl($"q={query}", mapLocationOptionsForRequest).ConfigureAwait(true); url += $"&umv={referenceBoundingBox.BottomLeft.LatitudeInDegrees},{referenceBoundingBox.BottomLeft.LongitudeInDegrees},{referenceBoundingBox.TopRight.LatitudeInDegrees},{referenceBoundingBox.TopRight.LongitudeInDegrees}"; return(await Request(url).ConfigureAwait(true)); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.StartObject) { var o = JObject.Load(reader); var topLeft = o.GetValue("topLeft")?.ToObject<GeoPoint>(); var bottomRight = o.GetValue("bottomRight")?.ToObject<GeoPoint>(); var bbox = new GeoBoundingBox(topLeft, bottomRight); if (objectType == typeof(string)) return bbox.ToString(); return bbox; } if (reader.TokenType == JsonToken.String) { GeoBoundingBox bbox = (string) reader.Value; return bbox; } return null; }
public void WriteJson_GeoBoundingBox_WritesExpectedOutput() { var input = new GeoBoundingBox( "MyField", new GeoPoint(59.9277542, 10.7190847), new GeoPoint(59.8881646, 10.7983952)); var stringWriter = new StringWriter(); var jsonWriter = new JsonTextWriter(stringWriter); var converter = new GeoBoundingBoxConverter(); converter.WriteJson(jsonWriter, input, new JsonSerializer()); stringWriter.Flush(); var result = stringWriter.ToString(); const string expected = "{\"geo_bounding_box\":{\"MyField\":{\"top_left\":{\"lat\":59.9277542,\"lon\":10.7190847},\"bottom_right\":{\"lat\":59.8881646,\"lon\":10.7983952}}}}"; Assert.Equal(expected, result); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.StartObject) { var o = JObject.Load(reader); var topLeft = o.GetValue(TopLeftPropertyName)?.ToObject <GeoLocation>(); var bottomRight = o.GetValue(BottomRightPropertyName)?.ToObject <GeoLocation>(); var bbox = new GeoBoundingBox(topLeft, bottomRight); if (objectType == typeof(string)) { return(bbox.ToString()); } return(bbox); } if (reader.TokenType == JsonToken.String) { GeoBoundingBox bbox = (string)reader.Value; return(bbox); } return(null); }
public void OnCalculateRouteFinished(Object results, Object routingError) { /* Calculation is done. Let's handle the result */ if (routingError == RoutingError.None) { Java.Util.AbstractList routeResults = (Java.Util.AbstractList)results; RouteResult route = routeResults.Get(0) as RouteResult; if (route != null) { /* Create a MapRoute so that it can be placed on the map */ parent.m_mapRoute = new MapRoute(route.Route); /* Show the maneuver number on top of the route */ parent.m_mapRoute.SetManeuverNumberVisible(true); /* Add the MapRoute to the map */ parent.m_map.AddMapObject(parent.m_mapRoute); /* * We may also want to make sure the map view is orientated properly * so the entire route can be easily seen. */ GeoBoundingBox gbb = route.Route.BoundingBox; parent.m_map.ZoomTo(gbb, Map.Animation.None, Map.MovePreserveOrientation); } else { Toast.MakeText(parent.m_activity, "Error:route results returned is not valid", ToastLength.Long).Show(); } } else { Toast.MakeText(parent.m_activity, "Error:route calculation returned error code: " + routingError, ToastLength.Long).Show(); } }
/// <summary> /// Constructs a <see cref="MapSceneOfBoundingBox"/> from the specified <see cref="GeoBoundingBox"/>. /// </summary> public MapSceneOfBoundingBox(GeoBoundingBox boundingBox) { BoundingBox = boundingBox; }
public void WhenAttemptingToCreateAGeoBoundingBoxWithValidArgs(string topLeft, string bottomRight) { var bbox = new GeoBoundingBox(topLeft, bottomRight); bbox.Should().NotBeNull(); }