// http://localhost:5000/api/map/Woodbar?size=800x600 public async Task <IActionResult> Get(string search, string size = "800x600", string zoom = "13") { // 1. make request to Google var key = "AIzaSyCixfkHHa7NI0Pi4_SHrL8wZS3VZiGek9s"; GoogleGeoCodeRoot geoCode = await googleApi.GetData <GoogleGeoCodeRoot>($"https://maps.googleapis.com/maps/api/geocode/json?address={search}&key={key}"); // 2. deserialize request from Google check GoogleStaticMaps map = new GoogleStaticMaps(search, Int32.Parse(zoom)); double lat = geoCode.results.ElementAt(0).geometry.location.lat; double lng = geoCode.results.ElementAt(0).geometry.location.lng; string latlng = $"{lat.ToString()},{lng.ToString()}"; map.markers[2].location.lat = lat; map.markers[2].location.lng = lng; API.ToJSON(geoCode); //string json = JsonConvert.SerializeObject(map); map.imageUrl = $"https://maps.googleapis.com/maps/api/staticmap?zoom={zoom}&size={size}&maptype=roadmap&markers=color:red|label:X|{latlng}"; // 3. return new structure back as Object return(Ok(new { map })); // string result = await client.GetStringAsync() // JSON... }
public async Task <GoogleStaticMaps> Load(string search, string size, int zoom) { var key = "AIzaSyCdNJl4Lm98QbzuYKdbcn9gCYawkmc_tlk"; var url = $"https://maps.googleapis.com/maps/api/geocode/json?address={search}&key={key}"; Google result = await googleApi.GetData <Google>(url); double lat = result.results.ElementAt(0).geometry.location.lat; //not sure we need this bit yet. double lng = result.results.ElementAt(0).geometry.location.lng; String LatLng = (lat.ToString() + "," + lng.ToString()); GoogleStaticMaps GSmaps = new GoogleStaticMaps(); GSmaps.imageUrl = $"https://maps.googleapis.com/maps/api/staticmap?zoom={zoom}&size={size}&maptype=roadmap&markers=color:red|label:X|{LatLng}"; GSmaps.timestamp = DateTime.Now.ToString(); GSmaps.searchTerm = search; //ViewBag add 32 GSmaps.zoomLevel = zoom; GSmaps.size = new Size { width = Int32.Parse(size.Split(new char[] { 'x' })[0]), height = Int32.Parse(size.Split(new char[] { 'x' })[1]) }; GSmaps.markers = new List <Marker> { new Marker { color = "red", label = "X", location = new GoogleStaticMapsX.Location { lat = lat, lng = lng } } }; return(GSmaps); }