protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.FirstView);

            var viewModel = (FirstViewModel) ViewModel;

            var mapFragment = (SupportMapFragment)SupportFragmentManager.FindFragmentById(Resource.Id.map);

            var options = new MarkerOptions();
            options.SetPosition(new LatLng(viewModel.Keith.Location.Lat, viewModel.Keith.Location.Lng));
            options.SetTitle("Keith");
            _keith = mapFragment.Map.AddMarker(options);

            var options2 = new MarkerOptions();
            options2.SetPosition(new LatLng(viewModel.Helen.Location.Lat, viewModel.Helen.Location.Lng));
            options2.SetTitle("Helen");
            _helen = mapFragment.Map.AddMarker(options2);

            var set = this.CreateBindingSet<FirstView, FirstViewModel>();
            set.Bind(_keith)
               .For(m => m.Position)
               .To(vm => vm.Keith.Location)
               .WithConversion(new LocationToLatLngValueConverter(), null);
            set.Bind(_helen)
               .For(m => m.Position)
               .To(vm => vm.Helen.Location)
               .WithConversion(new LocationToLatLngValueConverter(), null);
            set.Apply();

        }
        //
        // Marker related listeners.
        //
        public bool OnMarkerClick(Marker marker)
        {
            // This causes the marker at Perth to bounce into position when it is clicked.
            if (marker.Equals(mPerth)) {
                Handler handler = new Handler ();
                long start = SystemClock.UptimeMillis ();
                Projection proj = mMap.Projection;
                Point startPoint = proj.ToScreenLocation(PERTH);
                startPoint.Offset(0, -100);
                LatLng startLatLng = proj.FromScreenLocation(startPoint);
                long duration = 1500;

                IInterpolator interpolator = new BounceInterpolator();

                Runnable run = null;
                run = new Runnable (delegate {
                        long elapsed = SystemClock.UptimeMillis () - start;
                        float t = interpolator.GetInterpolation ((float) elapsed / duration);
                        double lng = t * PERTH.Longitude + (1 - t) * startLatLng.Longitude;
                        double lat = t * PERTH.Latitude + (1 - t) * startLatLng.Latitude;
                        marker.Position = (new LatLng(lat, lng));

                        if (t < 1.0) {
                            // Post again 16ms later.
                            handler.PostDelayed(run, 16);
                        }
                });
                handler.Post(run);
            }
            // We return false to indicate that we have not consumed the event and that we wish
            // for the default behavior to occur (which is for the camera to move such that the
            // marker is centered and for the marker's info window to open, if it has one).
            return false;
        }
Example #3
0
		public View GetInfoContents (Marker marker)
		{
			if (view == null) {
				var inflater = context.GetSystemService (Context.LayoutInflaterService).JavaCast<LayoutInflater> ();
				view = inflater.Inflate (Resource.Layout.InfoWindowLayout, null);
				var bikeView = view.FindViewById<ImageView> (Resource.Id.bikeImageView);
				var lockView = view.FindViewById<ImageView> (Resource.Id.lockImageView);
				bikeView.SetImageDrawable (bikeDrawable);
				lockView.SetImageDrawable (lockDrawable);
			}

			var name = view.FindViewById<TextView> (Resource.Id.InfoViewName);
			var bikes = view.FindViewById<TextView> (Resource.Id.InfoViewBikeNumber);
			var slots = view.FindViewById<TextView> (Resource.Id.InfoViewSlotNumber);
			var starButton = view.FindViewById<ToggleButton> (Resource.Id.StarButton); 

			var splitTitle = marker.Title.Split ('|');
			var displayName = splitTitle[1]
				.Split (new string[] { "-", " at " }, StringSplitOptions.RemoveEmptyEntries)
				.FirstOrDefault ();
			Id = int.Parse (splitTitle[0]);
			name.Text = (displayName ?? string.Empty).Trim ();
			var splitNumbers = marker.Snippet.Split ('|');
			bikes.Text = splitNumbers [0];
			slots.Text = splitNumbers [1];

			bool activated = favManager.GetFavoritesStationIds ().Contains (Id);
			starButton.Activated = activated;
			starButton.SetBackgroundDrawable (activated ? starOnDrawable : starOffDrawable);

			return view;
		}
		void FindMap ()
		{
			_map = (SupportFragmentManager.FindFragmentById (Resource.Id.map) as SupportMapFragment).Map;
			if (_map != null) {
				_map.MyLocationEnabled = true;

				_map.UiSettings.TiltGesturesEnabled = false;
				_map.UiSettings.RotateGesturesEnabled = false;

				_map.MapClick += OnMapClick;
				_map.MapLongClick += OnMapLongClick;
				_map.MyLocationChange += HandleMyLocationChange;
				_map.MarkerClick += OnMarkerClick;

				_map.SetInfoWindowAdapter (new InfoWindowAdapter ());

				// here because map should be already initialized
				// http://developer.android.com/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory.html
				_alarm_marker_normal = BitmapDescriptorFactory.FromResource (Resource.Drawable.marker_violet);
				_alarm_marker_normal_selected = BitmapDescriptorFactory.FromResource (Resource.Drawable.marker_violet_selected);
				_alarm_marker_disabled_selected = BitmapDescriptorFactory.FromResource (Resource.Drawable.marker_grey_selected);				
				_alarm_marker_disabled = BitmapDescriptorFactory.FromResource (Resource.Drawable.marker_grey);
                
				RefreshData ();

				_map.SetOnMapLoadedCallback (this);

				if (Mode == Mode.Add) {
					if (AlarmToAddMarker != null) {
						AlarmToAddMarker = _map.AddMarker (new MarkerOptions ().SetPosition (AlarmToAddMarker.Position).InvokeIcon (_alarm_marker_normal));
					}
				}
			}
		}
			public View GetInfoContents (Marker marker) {
				if (mOptions.CheckedRadioButtonId != Resource.Id.custom_info_contents) {
					// This means that the default info contents will be used.
					return null;
				}
				Render (marker, mContents);
				return mContents;
			}
			public View GetInfoWindow (Marker marker) {
				if (mOptions.CheckedRadioButtonId != Resource.Id.custom_info_window) {
					// This means that getInfoContents will be called.
					return null;
				}
				Render(marker, mWindow);
				return mWindow;
			}
		string GetIdentifier(Marker annotation)
		{
			Position annotationPosition = new Position (annotation.Position.Latitude, annotation.Position.Longitude);
			foreach (var pin in _pins) {
				if (pin.FormsPin.Position == annotationPosition)
					return pin.Identifier;	
			}
			return "";
		}
Example #8
0
                public bool OnMarkerClick(Android.Gms.Maps.Model.Marker marker)
                {
                    // select the appropriate row
                    int position = MapMarkerToRow(marker);

                    ListView.SmoothScrollToPosition(position);
                    (ListView.Adapter as GroupArrayAdapter).SetSelectedRow(position);

                    return(false);
                }
        private void CreateMarker()
        {
            var latLng = new LatLng(55.816887, 12.532878);

            var markerOptions = new MarkerOptions()
                .SetPosition(latLng)
                .Draggable(true);
            _meMarker = _map.AddMarker(markerOptions);
            _map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(latLng, 13));
        }
 public void OnMapReady (GoogleMap googleMap)
 {
     googleMap.MarkerDragEnd += (sender, e) => {
         mStreetViewPanorama.SetPosition (e.Marker.Position, 150);
     };
                         
     // Creates a draggable marker. Long press to drag.
     mMarker = googleMap.AddMarker (new MarkerOptions()
         .SetPosition (markerPosition)
         .SetIcon (BitmapDescriptorFactory.FromResource (Resource.Drawable.pegman))
         .Draggable(true));
 }
      public View GetInfoContents (Marker marker)
      {
         Point item = JsonConvert.DeserializeObject<Point> (marker.Snippet);
         bool needToRefresh = item.GetId != _info.GetId;
         if (needToRefresh) {
            SetContents (DeviceUtility.DeviceId, item.id, item.type);
         }

         _marker = marker;

         int customPopupId;
         if (item.GetMapItemType == MapItemType.Point) {
            customPopupId = Resource.Layout.CustomMarkerPopupPoint;
         } else {
            customPopupId = Resource.Layout.CustomMarkerPopupQuest;
         }
         var customPopup = _layoutInflater.Inflate (customPopupId, null);

         var nameTextView = customPopup.FindViewById<TextView> (Resource.Id.customInfoWindow_Name);
         if (nameTextView != null) {
            nameTextView.Text = string.Format ("Название: {0}", marker.Title);
            nameTextView.SetTextColor(Android.Graphics.Color.ParseColor("#bdbdbd"));
         }

         var latLonTextView = customPopup.FindViewById<TextView> (Resource.Id.customInfoWindow_LatLonTextView);
         if (latLonTextView != null) {
            latLonTextView.Text = string.Format ("Координаты: {0}; {1}", marker.Position.Latitude, marker.Position.Longitude);
            latLonTextView.SetTextColor(Android.Graphics.Color.ParseColor("#bdbdbd"));
         }

         if (item.GetMapItemType == MapItemType.Point) {
            var allianceTextView = customPopup.FindViewById<TextView> (Resource.Id.customInfoWindow_AllianceTextView);
            if (allianceTextView != null) {
               allianceTextView.Text = string.Format ("Альянс: {0}", _info.alliance);
               allianceTextView.SetTextColor(Android.Graphics.Color.ParseColor("#bdbdbd"));
            }

            var fractionTextView = customPopup.FindViewById<TextView> (Resource.Id.customInfoWindow_FractionTextView);
            if (fractionTextView != null) {
               fractionTextView.Text = string.Format ("Фракция: {0}", _info.fraction);
               fractionTextView.SetTextColor(Android.Graphics.Color.ParseColor("#bdbdbd"));
            }
         }

         var descriptionTextView = customPopup.FindViewById<TextView> (Resource.Id.customInfoWindow_DescriptionTextView);
         if (descriptionTextView != null) {
            descriptionTextView.Text = string.Format ("Описание: {0}", _info.description);
            descriptionTextView.SetTextColor(Android.Graphics.Color.ParseColor("#bdbdbd"));
         }

         return customPopup;
      }
        private void AddInitialPolarBarToMap()
        {
            MarkerOptions markerOptions = new MarkerOptions()
                .SetSnippet("Click me to go on vacation.")
                .SetPosition(LeaveFromHereToMaui)
                .SetTitle("Goto Maui");
            _polarBearMarker = _map.AddMarker(markerOptions);
            _polarBearMarker.ShowInfoWindow();

            _gotoMauiMarkerId = _polarBearMarker.Id;

            PositionPolarBearGroundOverlay(LeaveFromHereToMaui);
        }
Example #13
0
        /// <summary>
        /// Gets the info contents.
        /// </summary>
        /// <returns>The info contents.</returns>
        /// <param name="marker">Marker object.</param>
        public View GetInfoContents(Marker marker)
        {
            var inflater = Application.Context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;

            View v = inflater.Inflate(Resource.Layout.field_info_window, null);

            var title = v.FindViewById(Resource.Id.textViewName) as TextView;
            title.Text = marker.Title;

            var description = v.FindViewById(Resource.Id.textViewRows) as TextView;
            description.Text = marker.Snippet;

            return v;
        }
		public View GetInfoWindow(Marker p0)
		{
			string identifier = GetIdentifier (p0);

			//These would be the markers you want special views for
			switch (identifier) {
			case "Xamarin":
				return (_context as Activity).LayoutInflater.Inflate (Resource.Layout.XamarinPinView, _viewGroup, false);
			case "Train":
				return (_context as Activity).LayoutInflater.Inflate (Resource.Layout.TrainPinView, _viewGroup, false);
			}

			//This would be the default view that you want to set
			var view = new Android.Views.View (_context);

			return view;
		}
Example #15
0
                int MapMarkerToRow(Android.Gms.Maps.Model.Marker marker)
                {
                    // given a map marker, get the index of it in the row list
                    for (int i = 0; i < GroupEntries.Count; i++)
                    {
                        double currLatitude  = GroupEntries[i].Latitude;
                        double currLongitude = GroupEntries[i].Longitude;

                        if (marker.Position.Latitude == currLatitude &&
                            marker.Position.Longitude == currLongitude)
                        {
                            return(i);
                        }
                    }

                    return(-1);
                }
Example #16
0
                public void OnClick(int position, int buttonIndex)
                {
                    if (position < GroupEntries.Count)
                    {
                        if (buttonIndex == 0)
                        {
                            // select the row
                            (ListView.Adapter as GroupArrayAdapter).SetSelectedRow(position);

                            // scroll it into view
                            ListView.SmoothScrollToPosition(position);

                            // hide all other marker windows (if showing)
                            // go thru each marker and find the match, and then return it
                            foreach (Android.Gms.Maps.Model.Marker currMarker in MarkerList)
                            {
                                currMarker.HideInfoWindow( );
                            }

                            // validate the map because Google Play can error
                            if (Map != null)
                            {
                                // center that map marker
                                Android.Gms.Maps.Model.Marker marker = RowToMapMarker(position);
                                marker.ShowInfoWindow( );

                                Android.Gms.Maps.Model.LatLng centerMarker = new Android.Gms.Maps.Model.LatLng(marker.Position.Latitude, marker.Position.Longitude);

                                CameraUpdate camPos = CameraUpdateFactory.NewLatLngZoom(centerMarker, Map.CameraPosition.Zoom);
                                Map.AnimateCamera(camPos, 250, null);
                            }
                        }
                        else if (buttonIndex == 1)
                        {
                            // Ok! notify the parent they tapped Join, and it will launch the
                            // join group fragment! It's MARCH, FRIDAY THE 13th!!!! OH NOOOO!!!!
                            ParentTask.OnClick(this, position, GroupEntries[position]);
                            Rock.Mobile.Util.Debug.WriteLine(string.Format("Join neighborhood group in row {0}", position));
                        }
                    }
                    else
                    {
                        GetAdditionalGroups( );
                    }
                }
        public View GetInfoContents(Marker marker)
        {
            var customPopup = _layoutInflater.Inflate(Resource.Layout.info_window, null);

            var titleTextView = customPopup.FindViewById<TextView>(Resource.Id.lblNameValue);
            if (titleTextView != null)
            {
                titleTextView.Text = marker.Title;
            }

            var snippetTextView = customPopup.FindViewById<TextView>(Resource.Id.lblCommentValue);
            if (snippetTextView != null)
            {
                snippetTextView.Text = marker.Snippet;
            }

            return customPopup;
        }
Example #18
0
            private void Render(Marker marker, View view)
            {

                var resourceId = 0;
                if (parent._crueltyLookup.ContainsKey(marker.Id))
                {
                    CrueltySpot spot = parent._crueltyLookup[marker.Id];
                    if (spot.CrueltySpotCategory.IconName != null)
                    {
                        resourceId = parent.Resources.GetIdentifier(spot.CrueltySpotCategory.IconName.Replace(".png", ""), "drawable", parent.PackageName);
                    }
                }
                ((ImageView)view.FindViewById(Resource.Id.badge)).SetImageResource(resourceId);

                String title = marker.Title;
                TextView titleUi = ((TextView)view.FindViewById(Resource.Id.title));
                if (title != null)
                {
                    // Spannable string allows us to edit the formatting of the text.
                    SpannableString titleText = new SpannableString(title);

                    // FIXME: this somehow rejects to compile
                    //titleText.SetSpan (new ForegroundColorSpan(Color.Red), 0, titleText.Length, st);
                    titleUi.TextFormatted = (titleText);
                }
                else
                {
                    titleUi.Text = ("");
                }

                String snippet = marker.Snippet;
                TextView snippetUi = ((TextView)view.FindViewById(Resource.Id.snippet));
                if (snippet != null)
                {
                    SpannableString snippetText = new SpannableString(snippet);
                    //	snippetText.SetSpan(new ForegroundColorSpan(Color.Magenta), 0, 10, 0);
                    //	snippetText.SetSpan(new ForegroundColorSpan(Color.Blue), 12, 21, 0);
                    snippetUi.TextFormatted = (snippetText);
                }
                else
                {
                    snippetUi.Text = ("");
                }
            }
		public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
		{
			var pager = new ViewPager (inflater.Context) {
				Id = 0x34532,
				Adapter = new MonkeyPageAdapter (ChildFragmentManager),
			};
			pager.PageSelected += async (sender, e) => {
				var map = (SupportMapFragment)FragmentManager.FindFragmentById (Resource.Id.map);
				var monkeyName = ((MonkeyPageAdapter)pager.Adapter).GetMonkeyAtPosition (e.Position);
				var location = await WikipediaApi.FetchHabitatLocation (monkeyName);
				var latLng = new Android.Gms.Maps.Model.LatLng (location.Item1, location.Item2);
				map.Map.AnimateCamera (CameraUpdateFactory.NewLatLng (latLng), 250, null);
				if (existingMarker != null)
					existingMarker.Remove ();
				existingMarker = map.Map.AddMarker (new MarkerOptions ().SetPosition (latLng));
			};

			return pager;
		}
			private void Render (Marker marker, View view) {
				int badge;
				// Use the equals() method on a Marker to check for equals.  Do not use ==.
				if (marker.Equals(parent.mBrisbane)) {
					badge = Resource.Drawable.badge_qld;
				} else if (marker.Equals(parent.mAdelaide)) {
					badge = Resource.Drawable.badge_sa;
				} else if (marker.Equals(parent.mSydney)) {
					badge = Resource.Drawable.badge_nsw;
				} else if (marker.Equals(parent.mMelbourne)) {
					badge = Resource.Drawable.badge_victoria;
				} else if (marker.Equals(parent.mPerth)) {
					badge = Resource.Drawable.badge_wa;
				} else {
					// Passing 0 to setImageResource will clear the image view.
					badge = 0;
				}
				((ImageView) view.FindViewById (Resource.Id.badge)).SetImageResource (badge);
				
				String title = marker.Title;
				TextView titleUi = ((TextView) view.FindViewById (Resource.Id.title));
				if (title != null) {
					// Spannable string allows us to edit the formatting of the text.
					SpannableString titleText = new SpannableString (title);
					SpanTypes st = (SpanTypes) 0;
					// FIXME: this somehow rejects to compile
					//titleText.SetSpan (new ForegroundColorSpan(Color.Red), 0, titleText.Length, st);
					titleUi.TextFormatted = (titleText);
				} else {
					titleUi.Text = ("");
				}
				
				String snippet = marker.Snippet;
				TextView snippetUi = ((TextView) view.FindViewById(Resource.Id.snippet));
				if (snippet != null) {
					SpannableString snippetText = new SpannableString(snippet);
					snippetText.SetSpan(new ForegroundColorSpan(Color.Magenta), 0, 10, 0);
					snippetText.SetSpan(new ForegroundColorSpan(Color.Blue), 12, 21, 0);
					snippetUi.TextFormatted = (snippetText);
				} else {
					snippetUi.Text = ("");
				}
			}
Example #21
0
        public void OnLocationChanged(Location location)
        {
            _currentLocation = location;
            coord = new LatLng(location.Latitude, location.Longitude);
            CameraUpdate update = CameraUpdateFactory.NewLatLngZoom(coord, 17);

            map.AnimateCamera(update);

            if (currentLocationMarker != null) {
                currentLocationMarker.Position = coord;
            }
            else {
                var markerOptions = new MarkerOptions()
                    .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueBlue))
                    .SetPosition(coord)
                    .SetTitle("Current Position")
                    .SetSnippet("You are here");
                currentLocationMarker = map.AddMarker(markerOptions);
            }
        }
Example #22
0
        public async void OnLocationChanged(Android.Locations.Location location)
        {
            marker = null;
            Log.Debug(tag, "Location changed");
            latitude.Text = "Lat: " + location.Latitude.ToString();
            longitude.Text = "Lon: " + location.Longitude.ToString();
            provider.Text = "Provider: " + location.Provider.ToString();

            // PCL で Google Geocoding API Web サービスに Lat, Lon を投げて住所を取得しています。
            var addr = await getAddress.GetJsonAsync(location.Latitude, location.Longitude) ?? "取得できませんでした";
            Log.Debug("AddressResult", addr);
            address.Text = "Address: " + addr;

            // 取得した Lat, Lon を Map に投げます。
            map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(
                    new CameraPosition(
                        new LatLng(location.Latitude, location.Longitude), 14f, 0f, 0f)));
            marker = map.AddMarker(new MarkerOptions()
                .SetTitle(addr)
                .SetPosition(new LatLng(location.Latitude, location.Longitude)));
        }
 public void OnInfoWindowClick(Marker marker)
 {
     Toast.MakeText(BaseContext, "Click Info Window", ToastLength.Short).Show();
 }
        private void AddMarkersToMap()
        {
            // Uses a colored icon.
            mBrisbane = mMap.AddMarker(new MarkerOptions()
                                       .SetPosition(BRISBANE)
                                       .SetTitle("Brisbane")
                                       .SetSnippet("Population: 2,074,200")
                                       .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueAzure)));

            // Uses a custom icon.
            mSydney = mMap.AddMarker(new MarkerOptions()
                                     .SetPosition(SYDNEY)
                                     .SetTitle("Sydney")
                                     .SetSnippet("Population: 4,627,300")
                                     .SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.arrow)));

            // Creates a draggable marker. Long press to drag.
            mMelbourne = mMap.AddMarker(new MarkerOptions()
                                        .SetPosition(MELBOURNE)
                                        .SetTitle("Melbourne")
                                        .SetSnippet("Population: 4,137,400")
                                        .Draggable(true));

            // A few more markers for good measure.
            mPerth = mMap.AddMarker(new MarkerOptions()
                                    .SetPosition(PERTH)
                                    .SetTitle("Perth")
                                    .SetSnippet("Population: 1,738,800"));
            mAdelaide = mMap.AddMarker(new MarkerOptions()
                                       .SetPosition(ADELAIDE)
                                       .SetTitle("Adelaide")
                                       .SetSnippet("Population: 1,213,000"));

            // Creates a marker rainbow demonstrating how to create default marker icons of different
            // hues (colors).
            int numMarkersInRainbow = 12;
            for (int i = 0; i < numMarkersInRainbow; i++) {
                mMap.AddMarker(new MarkerOptions()
                               .SetPosition(new LatLng(
                    -30 + 10 * Math.Sin(i * Math.PI / (numMarkersInRainbow - 1)),
                    135 - 10 * Math.Cos(i * Math.PI / (numMarkersInRainbow - 1))))
                               .SetTitle("Marker " + i)
                               .SetIcon(BitmapDescriptorFactory.DefaultMarker(i * 360 / numMarkersInRainbow)));
            }
        }
 public void OnMarkerDragStart(Marker marker)
 {
     mTopText.Text = ("onMarkerDragStart");
 }
 public void OnMarkerDragEnd(Marker marker)
 {
     mTopText.Text = ("onMarkerDragEnd");
 }
 public void OnMarkerDrag(Marker marker)
 {
     mTopText.Text = ("onMarkerDrag.  Current Position: " + marker.Position);
 }
		public View GetInfoContents(Marker p0)
		{
			throw new NotImplementedException ();
		}
        private void MapOnMarkerClick(object sender, GoogleMap.MarkerClickEventArgs markerClickEventArgs)
        {
            markerClickEventArgs.Handled = true;

            Marker marker = markerClickEventArgs.Marker;
            if (marker.Id.Equals(_gotoMauiMarkerId))
            {
                PositionPolarBearGroundOverlay(InMaui);
                _map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(InMaui, 13));
                _gotoMauiMarkerId = null;
                _polarBearMarker.Remove();
                _polarBearMarker = null;
            }
            else
            {
                Toast.MakeText(this, String.Format("You clicked on Marker ID {0}", marker.Id), ToastLength.Short).Show();

            }
        }
 private bool IsItem(IMapModel item, Marker marker)
 {
     return item.Name == marker.Title &&
     item.Details == marker.Snippet &&
     item.Location.Latitude == marker.Position.Latitude &&
     item.Location.Longitude == marker.Position.Longitude;
 }
Example #31
0
        private void OnMyLocationButtonClick(object sender, GoogleMap.MyLocationButtonClickEventArgs e)
        {
            var myLocation = GetMyLocation();
            if (myLocation == null)
            {
                Logger.Log("Brak sygna³u GPS.");
                MessagingCenter.Send(_myMap, "DisplayAlert", new AlertMessage("B³¹d", "Brak sygna³u GPS."));
                return;
            }
            var myLatLng = new Android.Gms.Maps.Model.LatLng(myLocation.Latitude, myLocation.Longitude);

            // Create new starting marker.
            if (_startMarker == null)
            {
                var marker = new MarkerOptions();
                marker.SetPosition(myLatLng);
                marker.SetTitle("Od");
                marker.Draggable(true);
                // TODO: Custom start icon.

                _startMarker = _map.AddMarker(marker);
                _startMarker.ShowInfoWindow();
            }
            // Move existing marker.
            else
            {
                _startMarker.Position = myLatLng;
                _startMarker.ShowInfoWindow();
            }
            _map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(myLatLng, DefaultZoom));
        }
Example #32
0
        private void OnMapClick(object sender, GoogleMap.MapClickEventArgs e)
        {
            var latlng = e.Point;
            // Create new destination marker.
            if (_destinationMarker == null)
            {
                var marker = new MarkerOptions();
                marker.SetPosition(latlng);
                marker.SetTitle("Do");
                marker.Draggable(true);
                marker.SetSnippet("Punkt docelowy");
                // TODO: Custom destination icon.

                _destinationMarker = _map.AddMarker(marker);
                _destinationMarker.ShowInfoWindow();
            }
            // Move existing marker.
            else
            {
                _destinationMarker.Position = latlng;
                _destinationMarker.ShowInfoWindow();
            }
        }
Example #33
0
        private void OnBtnLocalizeClicked(MapPage mapPage)
        {
            var myLocation = GetMyLocation();
            if (myLocation == null)
            {
                Logger.Log("Brak sygna³u GPS.");
                MessagingCenter.Send(_myMap, "DisplayAlert", new AlertMessage("B³¹d", "Brak sygna³u GPS."));
                return;
            }
            var myLatLng = new Android.Gms.Maps.Model.LatLng(myLocation.Latitude, myLocation.Longitude);

            // Create new starting marker.
            if (_startMarker == null)
            {
                var marker = new MarkerOptions();
                marker.SetPosition(myLatLng);
                marker.SetTitle("Od");
                marker.Draggable(false);
                // TODO: Custom start icon.

                _startMarker = _map.AddMarker(marker);
                _startMarker.ShowInfoWindow();
            }
            // Move existing marker.
            else
            {
                _startMarker.Position = myLatLng;
            }
            _map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(myLatLng, DefaultZoom));

            // TODO: Display nearest stations.
            var nearestStations = App.Database.GetNearestStations(myLatLng.Latitude, myLatLng.Longitude, 5);
            for (var i = 0; i < nearestStations.Length; i++)
            {
                var station = nearestStations[i];
                var marker = new MarkerOptions();
                var latLng = new Android.Gms.Maps.Model.LatLng(station.latitude, station.longitude);
                marker.SetPosition(latLng);
                marker.SetTitle(string.Format("{0}. {1} - {2}", station.postId, station.postName, station.street));
                marker.Draggable(false);
                marker.SetSnippet("Wiêcej...");
                // TODO: Custom stations's icon.

                var mapMarker = _map.AddMarker(marker);
                var stationMarker = new StationMarker(station, mapMarker);
                _nearestMarkers.Add(stationMarker);
            }
        }
Example #34
0
                void UpdateMap(bool result)
                {
                    if (GroupEntries.Count > 0)
                    {
                        // update our list and display
                        SearchResultPrefix.Text = ConnectStrings.GroupFinder_Neighborhood;

                        (ListView.Adapter as GroupArrayAdapter).SetSelectedRow(0);

                        // for the map, ensure it's valid, because Google Play can fail
                        if (Map != null)
                        {
                            Map.Clear( );
                            MarkerList.Clear( );

                            Android.Gms.Maps.Model.LatLngBounds.Builder builder = new Android.Gms.Maps.Model.LatLngBounds.Builder();

                            // add the source position
                            Android.Gms.Maps.Model.MarkerOptions markerOptions = new Android.Gms.Maps.Model.MarkerOptions();
                            Android.Gms.Maps.Model.LatLng        pos           = new Android.Gms.Maps.Model.LatLng(SourceLocation.Latitude, SourceLocation.Longitude);
                            markerOptions.SetPosition(pos);
                            markerOptions.InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
                            builder.Include(pos);

                            Android.Gms.Maps.Model.Marker marker = Map.AddMarker(markerOptions);
                            MarkerList.Add(marker);

                            for (int i = 0; i < GroupEntries.Count; i++)
                            {
                                // add the positions to the map
                                markerOptions = new Android.Gms.Maps.Model.MarkerOptions();
                                pos           = new Android.Gms.Maps.Model.LatLng(GroupEntries[i].Latitude, GroupEntries[i].Longitude);
                                markerOptions.SetPosition(pos);
                                markerOptions.SetTitle(GroupEntries[i].Name);
                                markerOptions.SetSnippet(string.Format("{0:##.0} {1}", GroupEntries[i].DistanceFromSource, ConnectStrings.GroupFinder_MilesSuffix));

                                builder.Include(pos);

                                marker = Map.AddMarker(markerOptions);
                                MarkerList.Add(marker);
                            }

                            Android.Gms.Maps.Model.LatLngBounds bounds = builder.Build( );

                            int paddingInPixels = Math.Min(View.Width, (int)(View.Height * .1f));

                            CameraUpdate camPos = CameraUpdateFactory.NewLatLngBounds(bounds, paddingInPixels);
                            Map.AnimateCamera(camPos);

                            // show the info window for the first (closest) group
                            MarkerList[1].ShowInfoWindow( );
                        }
                    }
                    else
                    {
                        if (result == true)
                        {
                            // send the analytic and update our list
                            SearchResultPrefix.Text       = ConnectStrings.GroupFinder_NoGroupsFound;
                            SearchResultNeighborhood.Text = string.Empty;

                            (ListView.Adapter as GroupArrayAdapter).SetSelectedRow(-1);

                            // validate the map before using. Google Play can error
                            if (Map != null)
                            {
                                // no groups found, so move the camera to the default position
                                Android.Gms.Maps.Model.LatLng defaultPos = new Android.Gms.Maps.Model.LatLng(ConnectConfig.GroupFinder_DefaultLatitude, ConnectConfig.GroupFinder_DefaultLongitude);
                                CameraUpdate camPos = CameraUpdateFactory.NewLatLngZoom(defaultPos, ConnectConfig.GroupFinder_DefaultScale_Android);
                                Map.AnimateCamera(camPos);
                            }
                        }
                        else
                        {
                            // there was actually an error. Let them know.
                            SearchResultPrefix.Text       = ConnectStrings.GroupFinder_NetworkError;
                            SearchResultNeighborhood.Text = string.Empty;
                        }
                    }
                }