Advertisement
jmawebtech

ontapmap

Oct 22nd, 2012
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using Android.App;
  7. using Android.Content;
  8. using Android.OS;
  9. using Android.Runtime;
  10. using Android.Views;
  11. using Android.Widget;
  12.  
  13. //using Com.Google.Android.Maps;
  14. using Android.Graphics.Drawables;
  15. using Android.GoogleMaps;
  16. using MenuFinderAN.BusinessLogic.MenuFinderServiceReference;
  17. using MenuFinderAN.Database;
  18. using MenuFinderAN.Activities;
  19.  
  20. namespace MenuFinderAN
  21. {
  22.     class MyItemizedOverlay : ItemizedOverlay
  23.     {
  24.         private List<OverlayItem> overlayItems = new List<OverlayItem> ();
  25.         private Context context;
  26.        
  27.         public MyItemizedOverlay (Context context, Drawable drawable)
  28.             : base(BoundCenterBottom(drawable))
  29.         {
  30.             this.context = context;
  31.             Populate ();
  32.         }
  33.        
  34.         public override int Size ()
  35.         {
  36.             return overlayItems.Count;
  37.         }
  38.        
  39.         public void AddItem (GeoPoint p, string title, string snippet)
  40.         {
  41.             OverlayItem item = new OverlayItem (p, title, snippet);
  42.             overlayItems.Add (item);
  43.             Populate ();
  44.         }
  45.        
  46.         public List<OverlayItem> OverlayItems {
  47.             get { return overlayItems; }
  48.         }
  49.        
  50.         protected override bool OnTap (int index)
  51.         {
  52.             OverlayItem item = (OverlayItem)overlayItems.ElementAt (index);
  53.             MenuFinderANApplication app = ((MenuFinderANApplication)context.ApplicationContext);
  54.             RestaurantLocation restaurantLocation = app.RestaurantLocations.Where (a => a.Name == item.Title).FirstOrDefault ();
  55.             AlertDialog.Builder dialog = new AlertDialog.Builder (context);
  56.             dialog.SetTitle (item.Title);
  57.             dialog.SetMessage (item.Snippet);
  58.  
  59.             if (app.CurrentLocation != null) {
  60.                 dialog.SetPositiveButton ("Directions", delegate(object sender, DialogClickEventArgs e) {
  61.  
  62.                     double slat = (double)app.CurrentLocation.Latitude;
  63.                     double slng = (double)app.CurrentLocation.Longitude;
  64.                     string saddr = slat.ToString () + "," + slng.ToString ();
  65.                     string daddr = restaurantLocation.Latitude.ToString () + "," + restaurantLocation.Longitude.ToString ();
  66.                     string url = ("http://maps.google.com/maps?saddr=" + saddr + "&daddr=" + daddr);
  67.                     var intent = new Intent (Intent.ActionView, Android.Net.Uri.Parse (url));
  68.                     context.StartActivity (intent);
  69.                 });
  70.             }
  71.             dialog.SetNegativeButton ("Details", delegate(object sender, DialogClickEventArgs e) {
  72.                 app.CurrentRestaurantLocation = restaurantLocation;
  73.                 // Pass the selected object to the new view controller.
  74.                 context.StartActivity (typeof(RestaurantDetails));
  75.  
  76.             });
  77.             dialog.Show ();
  78.             return true;
  79.         }
  80.        
  81.         protected override Java.Lang.Object CreateItem (int i)
  82.         {
  83.             var item = overlayItems [i];
  84.             return item;
  85.         }
  86.  
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement