public async void OnMapReady(GoogleMap googleMap) { this.googleMap = googleMap; googleMap.MyLocationEnabled = true; this.googleMap.UiSettings.MyLocationButtonEnabled = true; googleMap.UiSettings.ScrollGesturesEnabled = true; MarkerOptions mrkerBagLocation = new MarkerOptions(); mrkerBagLocation.SetPosition(new LatLng(Double.Parse(ViewModel.BagLatitude), Double.Parse(ViewModel.BagLongitude))); mrkerBagLocation.SetTitle("Bag Location"); MarkerOptions mrkerUserLocation = new MarkerOptions(); mrkerUserLocation.SetPosition(new LatLng(47.639466, -122.130665)); mrkerUserLocation.SetTitle("Your Location"); googleMap.AddMarker(mrkerUserLocation); googleMap.AddMarker(mrkerBagLocation); googleMap.MoveCamera(CameraUpdateFactory.NewLatLng(new LatLng(47.639466, -122.130665))); var x = await GetRouteInfo(); RouteLine = GetPolylines(x); RouteLine.InvokeColor(-65536); RouteLine.InvokeWidth(5); Routes = googleMap.AddPolyline(RouteLine); }
public async void GetRouteInfo() { string response = string.Empty; try { await Task.Run(() => { URL url = new URL(string.Format("https://maps.googleapis.com/maps/api/directions/json?" + "origin={0},{1}&destination={2},{3}&key={4}", 47.636372, -122.126888, 47.639466, -122.130665, "AIzaSyCn2XMz_4-GjsAu2Ge1M6h8mFBVpResBYs")); HttpsURLConnection urlConnection = (HttpsURLConnection)url.OpenConnection(); urlConnection.Connect(); var stream = urlConnection.InputStream; using (var streamReader = new StreamReader(stream)) { response = streamReader.ReadToEnd(); } }); } catch (Exception e) { var x = e.Message; } if (Routes != null) { Routes.Remove(); } RouteLine = GetPolylines(response); RouteLine.InvokeColor(-65536); RouteLine.InvokeWidth(5); Routes = googleMap.AddPolyline(RouteLine); }