Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Android.App;
- using Android.Content;
- using Android.OS;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- //using Com.Google.Android.Maps;
- using Android.Graphics.Drawables;
- using Android.GoogleMaps;
- using MenuFinderAN.BusinessLogic.MenuFinderServiceReference;
- using MenuFinderAN.Database;
- using MenuFinderAN.Activities;
- namespace MenuFinderAN
- {
- class MyItemizedOverlay : ItemizedOverlay
- {
- private List<OverlayItem> overlayItems = new List<OverlayItem> ();
- private Context context;
- public MyItemizedOverlay (Context context, Drawable drawable)
- : base(BoundCenterBottom(drawable))
- {
- this.context = context;
- Populate ();
- }
- public override int Size ()
- {
- return overlayItems.Count;
- }
- public void AddItem (GeoPoint p, string title, string snippet)
- {
- OverlayItem item = new OverlayItem (p, title, snippet);
- overlayItems.Add (item);
- Populate ();
- }
- public List<OverlayItem> OverlayItems {
- get { return overlayItems; }
- }
- protected override bool OnTap (int index)
- {
- OverlayItem item = (OverlayItem)overlayItems.ElementAt (index);
- MenuFinderANApplication app = ((MenuFinderANApplication)context.ApplicationContext);
- RestaurantLocation restaurantLocation = app.RestaurantLocations.Where (a => a.Name == item.Title).FirstOrDefault ();
- AlertDialog.Builder dialog = new AlertDialog.Builder (context);
- dialog.SetTitle (item.Title);
- dialog.SetMessage (item.Snippet);
- if (app.CurrentLocation != null) {
- dialog.SetPositiveButton ("Directions", delegate(object sender, DialogClickEventArgs e) {
- double slat = (double)app.CurrentLocation.Latitude;
- double slng = (double)app.CurrentLocation.Longitude;
- string saddr = slat.ToString () + "," + slng.ToString ();
- string daddr = restaurantLocation.Latitude.ToString () + "," + restaurantLocation.Longitude.ToString ();
- string url = ("http://maps.google.com/maps?saddr=" + saddr + "&daddr=" + daddr);
- var intent = new Intent (Intent.ActionView, Android.Net.Uri.Parse (url));
- context.StartActivity (intent);
- });
- }
- dialog.SetNegativeButton ("Details", delegate(object sender, DialogClickEventArgs e) {
- app.CurrentRestaurantLocation = restaurantLocation;
- // Pass the selected object to the new view controller.
- context.StartActivity (typeof(RestaurantDetails));
- });
- dialog.Show ();
- return true;
- }
- protected override Java.Lang.Object CreateItem (int i)
- {
- var item = overlayItems [i];
- return item;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement