void AddPin(GooglePlaceNearbyItem item) { if (item.PlaceId == null || Math.Abs(item.Lat) < 0.0001 || Math.Abs(item.Lon) < 0.0001) { return; } if (item.Name == null) { item.Name = AppResources.NoName; } string rating = $"{String.Format("{0:0.0}", item.RatingD).Replace(".", string.Empty)}.png"; Device.BeginInvokeOnMainThread(() => { Pin pin = new Pin { Type = PinType.Place, Position = new Position(item.Lat, item.Lon), Label = item.Name, Icon = BitmapDescriptorFactory.FromBundle(rating), Tag = item }; map.Pins.Add(pin); }); }
public async Task <int> DeleteItemAsync(GooglePlaceNearbyItem item) { var rtn = await GetItemAsync(item.PlaceId); if (rtn != null) { return(await database.DeleteAsync(item)); } else { return(0); } }
public async Task <int> SaveItemAsync(GooglePlaceNearbyItem item) { var rtn = await GetItemAsync(item.PlaceId); if (rtn == null) { return(await database.InsertAsync(item)); } else { return(await database.UpdateAsync(item)); } }
private async void LoadPlaces(double?Lat = null, double?Lon = null, double?Rad = null, GooglePlaceNearbyItem append = null) { if (Lat == null) { Lat = PropertiesDictionary.Latitude; } if (Lon == null) { Lon = PropertiesDictionary.Longitude; } if (Rad == null) { Rad = PropertiesDictionary.Radius; } MessagingCenter.Send(this, "ShowActIndicator"); MessagingCenter.Send(this, "CheckMapVisible"); List <string> types = new List <string>() { "restaurant" }; List <GooglePlaceNearbyItem> rtn = new List <GooglePlaceNearbyItem>(); if (PropertiesDictionary.ShowGoogle) { List <string> keywords = new List <string>() { }; if (PropertiesDictionary.Keyword != "") { var splitted = PropertiesDictionary.Keyword.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); keywords = new List <string>(splitted); } rtn = await Restful.Inst.GoogleMapsPlaceNearbySearch( (double)Lat, (double)Lon, (double)Rad, types, keywords ); } if (append == null || !append.Types.Contains("restaurant")) { PlacesToShow = rtn; } else { rtn.Add(append); PlacesToShow = rtn; } MessagingCenter.Send(this, "HideActIndicator"); }
public MatnaPageViewModel() { // Properties (Commands) initilization OnSearchClicked = new Command(() => { SelectedItem = NoneItem; MessagingCenter.Send(this, "ShowSearch"); }); OnItemClicked = new Command((arg) => { try { SelectedItem = placesToShow.Find(x => x.PlaceId == arg.ToString()); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } }); OnFilterClicked = new Command(() => { MessagingCenter.Send(this, "ShowFilter"); }); OnListClicked = new Command(() => { MessagingCenter.Send(this, "ShowList"); }); OnLoadSavedClicked = new Command(async() => { var items = await App.MyPlacesDatabase.GetItemsAsync(); Device.BeginInvokeOnMainThread(() => { PlacesToShow = items; IsShowBookmark = true; SelectedItem = NoneItem; }); }); OnBackSavedClicked = new Command(() => { SelectedItem = NoneItem; PlacesToShow = new List <GooglePlaceNearbyItem>(); IsShowBookmark = false; }); OnLoadPlacesFromMapClicked = new Command(() => { SelectedItem = NoneItem; LoadPlaces(); }); OnDeselectItemClicked = new Command(() => { SelectedItem = NoneItem; }); OnRouteClicked = new Command(() => { Uri uri = new Uri($"https://www.google.com/maps/dir/?api=1&destination={SelectedItem.Name}&destination_place_id={selectedItem.PlaceId}&travelmode=transit"); MessagingCenter.Send(this, "OpenUri", uri); }); OnDetailClicked = new Command(() => { Uri uri = new Uri($"https://www.google.com/maps/search/?api=1&query={SelectedItem.Lat},{SelectedItem.Lon}&query_place_id={SelectedItem.PlaceId}"); MessagingCenter.Send(this, "OpenUri", uri); }); OnShareClicked = new Command(() => { CrossShare.Current.Share( new ShareMessage { Title = SelectedItem.Name, Text = SelectedItem.Vicinity, //Url = urlShareLabel.Text // Not necessary }, new ShareOptions { ChooserTitle = AppResources.Share, ExcludedUIActivityTypes = new[] { ShareUIActivityType.PostToFacebook } } ); }); OnSaveClicked = new Command(async() => { var item = placesToShow.Find(x => x.PlaceId == SelectedItem.PlaceId); SelectedItem = NoneItem; item.IsSaved = true; await App.MyPlacesDatabase.SaveItemAsync(item); SelectedItem = item; }); OnRemoveClicked = new Command(async() => { var item = placesToShow.Find(x => x.PlaceId == SelectedItem.PlaceId); SelectedItem = NoneItem; item.IsSaved = false; await App.MyPlacesDatabase.DeleteItemAsync(item); SelectedItem = item; }); // Initialize Data MessagingCenter.Unsubscribe <MatnaPage>(this, "CameraChanged"); MessagingCenter.Subscribe <MatnaPage>(this, "CameraChanged", (sender) => { // Currently does nothing. // Do not call Places API every time. Cost is way too high. }); MessagingCenter.Unsubscribe <AdViewControl, bool>(this, "ShowAd"); MessagingCenter.Subscribe <AdViewControl, bool>(this, "ShowAd", (sender, b) => { if (!IsShowAd) { IsShowAd = b; } }); MessagingCenter.Unsubscribe <MatnaPage, GooglePlaceNearbyItem>(this, "PinSelected"); MessagingCenter.Subscribe <MatnaPage, GooglePlaceNearbyItem>(this, "PinSelected", (sender, item) => { SelectedItem = item; }); MessagingCenter.Unsubscribe <MatnaPage>(this, "IsMapIdled"); MessagingCenter.Subscribe <MatnaPage>(this, "IsMapIdled", (sender) => { isMapIdled = true; }); MessagingCenter.Unsubscribe <SearchPage, string>(this, "OnPredictionSelected"); MessagingCenter.Subscribe <SearchPage, string>(this, "OnPredictionSelected", async(sender, str) => { // 1. Find item detail GooglePlaceNearbyItem item = await Restful.Inst.GoogleMapsPlaceNameFromDetails(str); // 2. Move to region MessagingCenter.Send(this, "MoveToLocation", new List <double>() { item.Lat, item.Lon, 1000 }); isMapIdled = false; while (!isMapIdled) { await Task.Delay(100); } // 3. LoadPlaces with defined Radius LoadPlaces(item.Lat, item.Lon, 1000, item); // 4. If item type is restaurant, add it to PlacesToShow; else ignore if (item.Types.Contains("restaurant")) { SelectedItem = item; } }); }