public async void getPlaces(double lat, double lon) { string httpheader = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + lat + "," + lon + "&radius=10000&types=parking&key=AIzaSyDGGzD_RjFpH8HyUMjYq29j6wj4o0tSw9c"; BasicGeoposition positiontest = new BasicGeoposition(); //test for json results var client = new HttpClient(); var result = await client.GetStringAsync(httpheader); PlacesResponse placeresponse = (PlacesResponse)JsonConvert.DeserializeObject <PlacesResponse>(result); int count = placeresponse.results.Length; if (placeresponse.status == "OK") { for (int i = 0; i < count; i++) { PushPin pushpin1 = new PushPin(); string name = placeresponse.results[i].name; positiontest.Latitude = placeresponse.results[i].geometry.location.lat; positiontest.Longitude = placeresponse.results[i].geometry.location.lng; Geopoint geopoint1 = new Geopoint(positiontest); AddPushPinOnMap(pushpin1, placeresponse, name, count, i, geopoint1); } } Pushpins.ItemsSource = pushpins; }
public void AddPushPinOnMap(PushPin pushpin, PlacesResponse response, string name, int max, int count, Geopoint geopoint) { MapIcon icon = new MapIcon(); icon.Location = geopoint; icon.Title = name; mapWithParkings.MapElements.Add(icon); }
public MainPage() { this.InitializeComponent(); //Base url for getting long & lat string baseUrl = "https://data.smartdublin.ie/cgi-bin/rtpi/busstopinformation?stopid="; //End url to get json formatted api string endUrl = "&format=json"; //Variable for storing station code selected string stationSelectedforCo; //Array to store all latitudes of all stations double[] latAllStations = new double[28]; //Array to store all longitudes of all stations double[] lonAllStations = new double[28]; //for loop runs through all stations for (int i = 0; i < stationCodes.Length; i++) { //Apply station[i] coded for geting station[i] long, lat & displaystopid stationSelectedforCo = stationCodes[i]; //Adapted from https://stackoverflow.com/questions/36516146/parsing-json-in-uwp //Creates new instance of httpClient HttpClient client = new HttpClient(); //gets client BaseAddress using manually built 'string', depending on station client.BaseAddress = new Uri(baseUrl + stationSelectedforCo + endUrl); //Accepts Json format client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Get response via url HttpResponseMessage response = client.GetAsync(baseUrl + stationSelectedforCo + endUrl).Result; //Populate result with response var result = response.Content.ReadAsStringAsync().Result; //Populate obj with 'readable' items via result var obj = JsonConvert.DeserializeObject <RootLocation>(result); //Get latitude & longitude of station string latStation = obj.results[0].latitude; string lonStation = obj.results[0].longitude; //Convert/parse latitude/longitude into doubles double doubleLatStation = double.Parse(latStation); double doubleLonStation = double.Parse(lonStation); //Apply longitude/latitude into correct index latAllStations[i] = doubleLatStation; lonAllStations[i] = doubleLonStation; } //Creates a list of landmarks var MyLandmarks = new List <MapElement>(); //Centers map on Ireland BasicGeoposition snPosition = new BasicGeoposition { Latitude = 53.4239, Longitude = -7.9407 }; Geopoint snPoint = new Geopoint(snPosition); //Used to populate map with landmarks var LandmarksLayer = new MapElementsLayer { ZIndex = 1, MapElements = MyLandmarks }; //Adds a layer to map so Landmarks can be added MapControl1.Layers.Add(LandmarksLayer); //Sets positon/zoom of map MapControl1.Center = snPoint; MapControl1.ZoomLevel = 8; // Add the MapControl and the specify maps authentication key. MapControl1.MapServiceToken = "4eHjP7348hDlfxfexoHq~b19fzIoJ9f9tKXS6zjtgzQ~AkcMoHnOY06TTP7cZlx7HU6p51K8tdzCES0s6AfLdGfIzxYbOiXZybD_DiYZ_nd0"; //creates new push pin PushPin pushPin = new PushPin(); //Populates map with pushpins via long & lat of each station, also includes station names for (int i = 0; i < lonAllStations.Length; i++) { pushPin.AddPushPin(latAllStations[i], lonAllStations[i]); MapIcon myIcon = new MapIcon(); myIcon.NormalizedAnchorPoint = new Point(0.5, 1.0); myIcon.Title = stationNames[i] + " Station"; MapControl1.MapElements.Add(myIcon); myIcon.Location = pushPin.MyGeopoint(i); } //Populates ComboBox for (int i = 0; i < stationNames.Length; i++) { sNames.Add(new DisplayItems() { ID = i, stationName = stationNames[i] }); } }//MainPage