public static String getLatFromAddress2(String s) { s = s.Replace("Suite", ""); s = s.Replace("suite", ""); s = s.Replace("Apt", ""); s = s.Replace("apt", ""); //Instance class use (Geocode) (Can be made from static/instance class) var geocodeRequest = new GeocodingRequest { Address = s, }; var geocodingEngine = new GeocodingEngine(); GeocodingResponse geocode = geocodingEngine.GetGeocode(geocodeRequest); Result match1 = null; try { match1 = geocode.Results.First(); } catch (Exception) { return "notfound"; } Double lat = match1.Geometry.Location.Latitude; return lat.ToString(); }
//SiteViewModel public static SiteCoord GetLocForAddress(string address) { GeocodingRequest geocodeRequest = new GeocodingRequest() { Address = address + ", " + ", Australia" }; GeocodingEngine geocodingEngine = new GeocodingEngine(); GeocodingResponse geocode = geocodingEngine.GetGeocode(geocodeRequest); SiteCoord sc = new SiteCoord(); sc.latitude = geocode.Results.FirstOrDefault().Geometry.Location.Latitude; sc.longitude = geocode.Results.FirstOrDefault().Geometry.Location.Longitude; return sc; }
public void ReverseGeocoding_ReturnsCorrectAddress() { var engine = new GeocodingEngine(); var request = new GeocodingRequest { Location = new Location(40.7141289, -73.9614074) }; var result = engine.GetGeocode(request); if (result.Status == Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(Status.OK, result.Status); Assert.AreEqual("285 Bedford Ave, Brooklyn, NY 11211, USA", result.Results.First().FormattedAddress); }
public static SiteCoord GetLocForAddress(string address) //SiteViewModel { GeocodingRequest geocodeRequest = new GeocodingRequest() { Address = address + ", " + ", Australia" }; GeocodingEngine geocodingEngine = new GeocodingEngine(); GeocodingResponse geocode = geocodingEngine.GetGeocode(geocodeRequest); SiteCoord sc = new SiteCoord(); sc.latitude = geocode.Results.FirstOrDefault().Geometry.Location.Latitude; sc.longitude = geocode.Results.FirstOrDefault().Geometry.Location.Longitude; return(sc); }
static void Main(string[] args) { //Static class use (Directions) DirectionsRequest directionsRequest = new DirectionsRequest() { Origin = "NYC, 5th and 39", Destination = "Philladephia, Chesnut and Wallnut", }; DirectionsResponse directions = MapsAPI.GetDirections(directionsRequest); Console.WriteLine(directions); //Instance class use (Geocode) GeocodingRequest geocodeRequest = new GeocodingRequest() { Address = "new york city", }; GeocodingEngine geocodingEngine = new GeocodingEngine(); GeocodingResponse geocode = geocodingEngine.GetGeocode(geocodeRequest); Console.WriteLine(geocode); // Static maps API - get static map of with the path of the directions request StaticMapsEngine staticMapGenerator = new StaticMapsEngine(); //Path from previos directions request IEnumerable <Step> steps = directions.Routes.First().Legs.First().Steps; // All start locations IList <ILocation> path = steps.Select(step => step.StartLocation).ToList <ILocation>(); // also the end location of the last step path.Add(steps.Last().EndLocation); string url = staticMapGenerator.GenerateStaticMapURL(new StaticMapRequest(new Location(40.38742, -74.55366), 9, new ImageSize(800, 400)) { Pathes = new List <Path>() { new Path() { Style = new PathStyle() { Color = "red" }, Locations = path } } }); Console.WriteLine("Map with path: " + url); //Instance class - Async! (Elevation) ElevationRequest elevationRequest = new ElevationRequest() { Locations = new Location[] { new Location(54, 78) }, }; ElevationEngine elevationEngine = new ElevationEngine(); elevationEngine.BeginGetElevation(elevationRequest, ar => { ElevationResponse elevation = elevationEngine.EndGetElevation(ar); Console.WriteLine(elevation); }, null); Console.WriteLine("Finised! (But wait .. async elevation request should get response soon)"); Console.ReadKey(); }