diff --git a/XFGoogleMapSample/Droid/XFGoogleMapSample.Droid.csproj b/XFGoogleMapSample/Droid/XFGoogleMapSample.Droid.csproj
index eb71ccc0..36995bba 100644
--- a/XFGoogleMapSample/Droid/XFGoogleMapSample.Droid.csproj
+++ b/XFGoogleMapSample/Droid/XFGoogleMapSample.Droid.csproj
@@ -91,10 +91,10 @@
..\packages\Xamarin.GooglePlayServices.Maps.29.0.0.1\lib\MonoAndroid41\Xamarin.GooglePlayServices.Maps.dll
- ..\packages\Xamarin.Forms.GoogleMaps.1.4.1\lib\MonoAndroid10\Xamarin.Forms.GoogleMaps.Android.dll
+ ..\packages\Xamarin.Forms.GoogleMaps.1.5.0\lib\MonoAndroid10\Xamarin.Forms.GoogleMaps.Android.dll
- ..\packages\Xamarin.Forms.GoogleMaps.1.4.1\lib\MonoAndroid10\Xamarin.Forms.GoogleMaps.dll
+ ..\packages\Xamarin.Forms.GoogleMaps.1.5.0\lib\MonoAndroid10\Xamarin.Forms.GoogleMaps.dll
diff --git a/XFGoogleMapSample/Droid/packages.config b/XFGoogleMapSample/Droid/packages.config
index 37cadb77..ef3d1ac2 100644
--- a/XFGoogleMapSample/Droid/packages.config
+++ b/XFGoogleMapSample/Droid/packages.config
@@ -9,7 +9,7 @@
-
+
diff --git a/XFGoogleMapSample/XFGoogleMapSample/BasicMapPage.xaml.cs b/XFGoogleMapSample/XFGoogleMapSample/BasicMapPage.xaml.cs
index f6a2b36d..9114484b 100644
--- a/XFGoogleMapSample/XFGoogleMapSample/BasicMapPage.xaml.cs
+++ b/XFGoogleMapSample/XFGoogleMapSample/BasicMapPage.xaml.cs
@@ -49,6 +49,22 @@ public BasicMapPage()
};
switchIsShowingUser.IsToggled = map.IsShowingUser;
+ // Map Clicked
+ map.MapClicked += (sender, e) =>
+ {
+ var lat = e.Point.Latitude.ToString("0.000");
+ var lng = e.Point.Longitude.ToString("0.000");
+ this.DisplayAlert("MapClicked", $"{lat}/{lng}", "CLOSE");
+ };
+
+ // Map Long clicked
+ map.MapLongClicked += (sender, e) =>
+ {
+ var lat = e.Point.Latitude.ToString("0.000");
+ var lng = e.Point.Longitude.ToString("0.000");
+ this.DisplayAlert("MapLongClicked", $"{lat}/{lng}", "CLOSE");
+ };
+
// Geocode
buttonGeocode.Clicked += async (sender, e) =>
{
diff --git a/XFGoogleMapSample/XFGoogleMapSample/CustomPinsPage.xaml b/XFGoogleMapSample/XFGoogleMapSample/CustomPinsPage.xaml
index 44a0009f..56bf6909 100644
--- a/XFGoogleMapSample/XFGoogleMapSample/CustomPinsPage.xaml
+++ b/XFGoogleMapSample/XFGoogleMapSample/CustomPinsPage.xaml
@@ -17,65 +17,84 @@
+
-
+
+ Grid.Row="0"
+ Grid.Column="0"/>
+ Grid.Row="0"
+ Grid.Column="1"/>
+ Grid.Row="0"
+ Grid.Column="2"/>
+ Grid.Row="1"
+ Grid.Column="0"/>
+ Grid.Row="1"
+ Grid.Column="1"/>
+ Grid.Row="1"
+ Grid.Column="2"/>
+ Grid.Row="2"
+ Grid.Column="0"/>
+ Grid.Row="2"
+ Grid.Column="1"/>
+ Grid.Row="2"
+ Grid.Column="2"/>
+
+
+
+
+
+
+
+
diff --git a/XFGoogleMapSample/XFGoogleMapSample/CustomPinsPage.xaml.cs b/XFGoogleMapSample/XFGoogleMapSample/CustomPinsPage.xaml.cs
index 86d9f474..a7257592 100644
--- a/XFGoogleMapSample/XFGoogleMapSample/CustomPinsPage.xaml.cs
+++ b/XFGoogleMapSample/XFGoogleMapSample/CustomPinsPage.xaml.cs
@@ -52,7 +52,7 @@ public CustomPinsPage()
var switches = new Switch[] { switchPinColor, switchPinBundle, switchPinStream };
foreach (var sw in switches)
{
- sw.Toggled += (sender, e) =>
+ sw.Toggled += (sender, e) =>
{
if (!e.Value || _dirty)
return;
@@ -75,7 +75,7 @@ public CustomPinsPage()
buttonPinColor.Items.Add(c.Item1);
}
- buttonPinColor.SelectedIndexChanged += (_, e) =>
+ buttonPinColor.SelectedIndexChanged += (_, e) =>
{
buttonPinColor.BackgroundColor = _colors[buttonPinColor.SelectedIndex].Item2;
UpdatePinIcon();
@@ -107,7 +107,7 @@ public CustomPinsPage()
buttonPinStream.SelectedIndex = 0;
// Set to null
- buttonPinSetToNull.Clicked += (sender, e) =>
+ buttonPinSetToNull.Clicked += (sender, e) =>
{
_pinTokyo.Icon = null;
foreach (var sw in switches)
@@ -116,6 +116,23 @@ public CustomPinsPage()
}
};
+ // Pin Draggable
+ switchIsDraggable.Toggled += (sender, e) =>
+ {
+ _pinTokyo.IsDraggable = switchIsDraggable.IsToggled;
+ };
+
+ map.PinDragStart += (_, e) => labelDragStatus.Text = $"DragStart - {PrintPin(e.Pin)}";
+ map.PinDragging += (_, e) => labelDragStatus.Text = $"Dragging - {PrintPin(e.Pin)}";
+ map.PinDragEnd += (_, e) => labelDragStatus.Text = $"DragEnd - {PrintPin(e.Pin)}";
+
+ switchIsDraggable.IsToggled = true;
+
+ }
+
+ private string PrintPin(Pin pin)
+ {
+ return $"{pin.Label}({pin.Position.Latitude.ToString("0.000")},{pin.Position.Longitude.ToString("0.000")})";
}
protected override async void OnAppearing()
@@ -126,9 +143,9 @@ protected override async void OnAppearing()
await Task.Delay(1000); // workaround for #30 [Android]Map.Pins.Add doesn't work when page OnAppearing
+ _pinTokyo.IsDraggable = true;
map.Pins.Add(_pinTokyo);
map.MoveToRegion(MapSpan.FromCenterAndRadius(_pinTokyo.Position, Distance.FromMeters(5000)));
-
}
void UpdatePinIcon()
diff --git a/XFGoogleMapSample/XFGoogleMapSample/XFGoogleMapSample.csproj b/XFGoogleMapSample/XFGoogleMapSample/XFGoogleMapSample.csproj
index fef3f30f..b9c8c7cd 100644
--- a/XFGoogleMapSample/XFGoogleMapSample/XFGoogleMapSample.csproj
+++ b/XFGoogleMapSample/XFGoogleMapSample/XFGoogleMapSample.csproj
@@ -86,7 +86,7 @@
..\packages\Xamarin.Forms.2.3.0.49\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Platform.dll
- ..\packages\Xamarin.Forms.GoogleMaps.1.4.1\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Xamarin.Forms.GoogleMaps.dll
+ ..\packages\Xamarin.Forms.GoogleMaps.1.5.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Xamarin.Forms.GoogleMaps.dll
diff --git a/XFGoogleMapSample/XFGoogleMapSample/packages.config b/XFGoogleMapSample/XFGoogleMapSample/packages.config
index 5fda333d..b38c6038 100644
--- a/XFGoogleMapSample/XFGoogleMapSample/packages.config
+++ b/XFGoogleMapSample/XFGoogleMapSample/packages.config
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/XFGoogleMapSample/iOS/XFGoogleMapSample.iOS.csproj b/XFGoogleMapSample/iOS/XFGoogleMapSample.iOS.csproj
index f4249e10..737912fb 100644
--- a/XFGoogleMapSample/iOS/XFGoogleMapSample.iOS.csproj
+++ b/XFGoogleMapSample/iOS/XFGoogleMapSample.iOS.csproj
@@ -107,10 +107,10 @@
..\packages\Xamarin.Google.iOS.Maps.1.13.1.0\lib\Xamarin.iOS10\Google.Maps.dll
- ..\packages\Xamarin.Forms.GoogleMaps.1.4.1\lib\Xamarin.iOS10\Xamarin.Forms.GoogleMaps.iOS.dll
+ ..\packages\Xamarin.Forms.GoogleMaps.1.5.0\lib\Xamarin.iOS10\Xamarin.Forms.GoogleMaps.iOS.dll
- ..\packages\Xamarin.Forms.GoogleMaps.1.4.1\lib\Xamarin.iOS10\Xamarin.Forms.GoogleMaps.dll
+ ..\packages\Xamarin.Forms.GoogleMaps.1.5.0\lib\Xamarin.iOS10\Xamarin.Forms.GoogleMaps.dll
diff --git a/XFGoogleMapSample/iOS/packages.config b/XFGoogleMapSample/iOS/packages.config
index da42c1da..bb752b8e 100644
--- a/XFGoogleMapSample/iOS/packages.config
+++ b/XFGoogleMapSample/iOS/packages.config
@@ -2,6 +2,6 @@
-
+
\ No newline at end of file
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Extensions/LatLngExtensions.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Extensions/LatLngExtensions.cs
new file mode 100644
index 00000000..33ded936
--- /dev/null
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Extensions/LatLngExtensions.cs
@@ -0,0 +1,13 @@
+using System;
+using Android.Gms.Maps.Model;
+namespace Xamarin.Forms.GoogleMaps.Android.Extensions
+{
+ internal static class LatLngExtensions
+ {
+ public static Position ToPosition(this LatLng self)
+ {
+ return new Position(self.Latitude, self.Longitude);
+ }
+ }
+}
+
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Logics/PinLogic.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Logics/PinLogic.cs
index 750b1611..c1241f6b 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Logics/PinLogic.cs
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Logics/PinLogic.cs
@@ -15,6 +15,9 @@ internal class PinLogic : DefaultPinLogic
protected override IList GetItems(Map map) => map.Pins;
private volatile bool _onMarkerEvent = false;
+ private Pin _draggingPin;
+ private volatile bool _withoutUpdateNative = false;
+
internal override void Register(GoogleMap oldNativeMap, Map oldMap, GoogleMap newNativeMap, Map newMap)
{
@@ -25,6 +28,9 @@ internal override void Register(GoogleMap oldNativeMap, Map oldMap, GoogleMap ne
newNativeMap.InfoWindowClick += OnInfoWindowClick;
newNativeMap.MarkerClick += OnMakerClick;
newNativeMap.InfoWindowClose += OnInfoWindowClose;
+ newNativeMap.MarkerDragStart += OnMarkerDragStart;
+ newNativeMap.MarkerDragEnd += OnMarkerDragEnd;
+ newNativeMap.MarkerDrag += OnMarkerDrag;
}
}
@@ -32,6 +38,9 @@ internal override void Unregister(GoogleMap nativeMap, Map map)
{
if (nativeMap != null)
{
+ nativeMap.MarkerDrag -= OnMarkerDrag;
+ nativeMap.MarkerDragEnd -= OnMarkerDragEnd;
+ nativeMap.MarkerDragStart -= OnMarkerDragStart;
nativeMap.MarkerClick -= OnMakerClick;
nativeMap.InfoWindowClose -= OnInfoWindowClose;
nativeMap.InfoWindowClick -= OnInfoWindowClick;
@@ -46,7 +55,8 @@ protected override Marker CreateNativeItem(Pin outerItem)
.SetPosition(new LatLng(outerItem.Position.Latitude, outerItem.Position.Longitude))
.SetTitle(outerItem.Label)
.SetSnippet(outerItem.Address)
- .SetSnippet(outerItem.Address);
+ .SetSnippet(outerItem.Address)
+ .Draggable(outerItem.IsDraggable);
if (outerItem.Icon != null)
{
@@ -125,6 +135,38 @@ void OnInfoWindowClose(object sender, GoogleMap.InfoWindowCloseEventArgs e)
}
}
+ void OnMarkerDragStart(object sender, GoogleMap.MarkerDragStartEventArgs e)
+ {
+ // lookup pin
+ _draggingPin = LookupPin(e.Marker);
+
+ if (_draggingPin != null)
+ {
+ UpdatePositionWithoutMove(_draggingPin, e.Marker.Position.ToPosition());
+ Map.SendPinDragStart(_draggingPin);
+ }
+ }
+
+ void OnMarkerDrag(object sender, GoogleMap.MarkerDragEventArgs e)
+ {
+ if (_draggingPin != null)
+ {
+ UpdatePositionWithoutMove(_draggingPin, e.Marker.Position.ToPosition());
+ Map.SendPinDragging(_draggingPin);
+ }
+ }
+
+ void OnMarkerDragEnd(object sender, GoogleMap.MarkerDragEndEventArgs e)
+ {
+ if (_draggingPin != null)
+ {
+ UpdatePositionWithoutMove(_draggingPin, e.Marker.Position.ToPosition());
+ Map.SendPinDragEnd(_draggingPin);
+ _draggingPin = null;
+ }
+ _withoutUpdateNative = false;
+ }
+
internal override void OnMapPropertyChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == Map.SelectedPinProperty.PropertyName)
@@ -152,30 +194,16 @@ void UpdateSelectedPin(Pin pin)
}
}
- protected override void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
+ void UpdatePositionWithoutMove(Pin pin, Position position)
{
- base.OnItemPropertyChanged(sender, e);
-
- var pin = sender as Pin;
- var marker = pin?.NativeObject as Marker;
- if (marker == null)
- return;
-
- if (e.PropertyName == Pin.LabelProperty.PropertyName)
- {
- marker.Title = pin.Label;
- }
- else if (e.PropertyName == Pin.AddressProperty.PropertyName)
- {
- marker.Snippet = pin.Address;
- }
- else if (e.PropertyName == Pin.TypeProperty.PropertyName)
+ try
{
- /* no-op */
+ _withoutUpdateNative = true;
+ pin.Position = position;
}
- else if (e.PropertyName == Pin.PositionProperty.PropertyName)
+ finally
{
- marker.Position = pin.Position.ToLatLng();
+ _withoutUpdateNative = false;
}
}
@@ -186,7 +214,12 @@ protected override void OnUpdateLabel(Pin outerItem, Marker nativeItem)
=> nativeItem.Title = outerItem.Label;
protected override void OnUpdatePosition(Pin outerItem, Marker nativeItem)
- => nativeItem.Position = outerItem.Position.ToLatLng();
+ {
+ if (!_withoutUpdateNative)
+ {
+ nativeItem.Position = outerItem.Position.ToLatLng();
+ }
+ }
protected override void OnUpdateType(Pin outerItem, Marker nativeItem)
{
@@ -198,6 +231,11 @@ protected override void OnUpdateIcon(Pin outerItem, Marker nativeItem)
nativeItem.SetAnchor(0.5f, 1f);
nativeItem.SetInfoWindowAnchor(0.5f, 0f);
}
+
+ protected override void OnUpdateIsDraggable(Pin outerItem, Marker nativeItem)
+ {
+ nativeItem.Draggable = outerItem?.IsDraggable ?? false;
+ }
}
}
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/MapRenderer.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/MapRenderer.cs
index 413f54f8..963e5c10 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/MapRenderer.cs
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/MapRenderer.cs
@@ -11,11 +11,14 @@
using Xamarin.Forms.GoogleMaps.Internals;
using Xamarin.Forms.GoogleMaps.Logics.Android;
using Xamarin.Forms.GoogleMaps.Logics;
+using Xamarin.Forms.GoogleMaps.Android.Extensions;
namespace Xamarin.Forms.GoogleMaps.Android
{
public class MapRenderer : ViewRenderer,
- GoogleMap.IOnCameraChangeListener
+ GoogleMap.IOnCameraChangeListener,
+ GoogleMap.IOnMapClickListener,
+ GoogleMap.IOnMapLongClickListener
{
readonly BaseLogic[] _logics;
@@ -81,6 +84,8 @@ protected override void OnElementChanged(ElementChangedEventArgs e)
#pragma warning disable 618
oldMapView.Map.SetOnCameraChangeListener(null);
+ oldMapView.Map.SetOnMapClickListener(null);
+ oldMapView.Map.SetOnMapLongClickListener(null);
#pragma warning restore 618
}
@@ -91,6 +96,8 @@ protected override void OnElementChanged(ElementChangedEventArgs e)
if (map != null)
{
map.SetOnCameraChangeListener(this);
+ map.SetOnMapClickListener(this);
+ map.SetOnMapLongClickListener(this);
map.UiSettings.ZoomControlsEnabled = Map.HasZoomEnabled;
map.UiSettings.ZoomGesturesEnabled = Map.HasZoomEnabled;
map.UiSettings.ScrollGesturesEnabled = Map.HasScrollEnabled;
@@ -211,6 +218,16 @@ public void OnCameraChange(CameraPosition pos)
UpdateVisibleRegion(pos.Target);
}
+ public void OnMapClick(LatLng point)
+ {
+ Map.SendMapClicked(point.ToPosition());
+ }
+
+ public void OnMapLongClick(LatLng point)
+ {
+ Map.SendMapLongClicked(point.ToPosition());
+ }
+
void UpdateVisibleRegion(LatLng pos)
{
var map = NativeMap;
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Properties/GobalAssemblyInfo.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Properties/GobalAssemblyInfo.cs
index 740e2eca..d0f9feb9 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Properties/GobalAssemblyInfo.cs
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Properties/GobalAssemblyInfo.cs
@@ -4,5 +4,5 @@
[assembly: AssemblyProduct("Xamarin.Forms.GoogleMaps")]
[assembly: AssemblyCopyright("Copyright © amay077. 2016")]
[assembly: AssemblyTrademark("")]
-[assembly: AssemblyVersion("1.4.1.0")]
-[assembly: AssemblyFileVersion("1.4.1.0")]
\ No newline at end of file
+[assembly: AssemblyVersion("1.5.0.0")]
+[assembly: AssemblyFileVersion("1.5.0.0")]
\ No newline at end of file
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Xamarin.Forms.GoogleMaps.Android.csproj b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Xamarin.Forms.GoogleMaps.Android.csproj
index 92d408cd..007c4e82 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Xamarin.Forms.GoogleMaps.Android.csproj
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Xamarin.Forms.GoogleMaps.Android.csproj
@@ -105,6 +105,7 @@
+
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/Extensions/CLLocationCoordinate2DExtensions.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/Extensions/CLLocationCoordinate2DExtensions.cs
new file mode 100644
index 00000000..27cd2e5c
--- /dev/null
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/Extensions/CLLocationCoordinate2DExtensions.cs
@@ -0,0 +1,15 @@
+using System;
+using CoreLocation;
+
+namespace Xamarin.Forms.GoogleMaps.iOS.Extensions
+{
+ internal static class CLLocationCoordinate2DExtensions
+ {
+ public static Position ToPosition(this CLLocationCoordinate2D self)
+ {
+ return new Position(self.Latitude, self.Longitude);
+ }
+ }
+}
+
+
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/Logics/PinLogic.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/Logics/PinLogic.cs
index f6e75100..d85fd442 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/Logics/PinLogic.cs
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/Logics/PinLogic.cs
@@ -11,7 +11,9 @@ internal class PinLogic : DefaultPinLogic
{
protected override IList GetItems(Map map) => map.Pins;
- bool _onMarkerEvent;
+ private bool _onMarkerEvent;
+ private Pin _draggingPin;
+ private volatile bool _withoutUpdateNative = false;
internal override void Register(MapView oldNativeMap, Map oldMap, MapView newNativeMap, Map newMap)
{
@@ -22,6 +24,9 @@ internal override void Register(MapView oldNativeMap, Map oldMap, MapView newNat
newNativeMap.InfoTapped += OnInfoTapped;
newNativeMap.TappedMarker = HandleGMSTappedMarker;
newNativeMap.InfoClosed += InfoWindowClosed;
+ newNativeMap.DraggingMarkerStarted += DraggingMarkerStarted;
+ newNativeMap.DraggingMarkerEnded += DraggingMarkerEnded;
+ newNativeMap.DraggingMarker += DraggingMarker;
}
}
@@ -30,6 +35,9 @@ internal override void Unregister(MapView nativeMap, Map map)
{
if (nativeMap != null)
{
+ nativeMap.DraggingMarker -= DraggingMarker;
+ nativeMap.DraggingMarkerEnded -= DraggingMarkerEnded;
+ nativeMap.DraggingMarkerStarted -= DraggingMarkerStarted;
nativeMap.InfoClosed -= InfoWindowClosed;
nativeMap.TappedMarker = null;
nativeMap.InfoTapped -= OnInfoTapped;
@@ -43,6 +51,7 @@ protected override Marker CreateNativeItem(Pin outerItem)
var nativeMarker = Marker.FromPosition(outerItem.Position.ToCoord());
nativeMarker.Title = outerItem.Label;
nativeMarker.Snippet = outerItem.Address ?? string.Empty;
+ nativeMarker.Draggable = outerItem.IsDraggable;
if (outerItem.Icon != null)
{
@@ -134,6 +143,50 @@ void InfoWindowClosed(object sender, GMSMarkerEventEventArgs e)
}
}
+ void DraggingMarkerStarted(object sender, GMSMarkerEventEventArgs e)
+ {
+ // lookup pin
+ _draggingPin = LookupPin(e.Marker);
+
+ if (_draggingPin != null)
+ {
+ UpdatePositionWithoutMove(_draggingPin, e.Marker.Position.ToPosition());
+ Map.SendPinDragStart(_draggingPin);
+ }
+ }
+
+ void DraggingMarkerEnded(object sender, GMSMarkerEventEventArgs e)
+ {
+ if (_draggingPin != null)
+ {
+ UpdatePositionWithoutMove(_draggingPin, e.Marker.Position.ToPosition());
+ Map.SendPinDragEnd(_draggingPin);
+ _draggingPin = null;
+ }
+ }
+
+ void DraggingMarker(object sender, GMSMarkerEventEventArgs e)
+ {
+ if (_draggingPin != null)
+ {
+ UpdatePositionWithoutMove(_draggingPin, e.Marker.Position.ToPosition());
+ Map.SendPinDragging(_draggingPin);
+ }
+ }
+
+ void UpdatePositionWithoutMove(Pin pin, Position position)
+ {
+ try
+ {
+ _withoutUpdateNative = true;
+ pin.Position = position;
+ }
+ finally
+ {
+ _withoutUpdateNative = false;
+ }
+ }
+
protected override void OnUpdateAddress(Pin outerItem, Marker nativeItem)
=> nativeItem.Snippet = outerItem.Address;
@@ -141,7 +194,12 @@ protected override void OnUpdateLabel(Pin outerItem, Marker nativeItem)
=> nativeItem.Title = outerItem.Label;
protected override void OnUpdatePosition(Pin outerItem, Marker nativeItem)
- => nativeItem.Position = outerItem.Position.ToCoord();
+ {
+ if (!_withoutUpdateNative)
+ {
+ nativeItem.Position = outerItem.Position.ToCoord();
+ }
+ }
protected override void OnUpdateType(Pin outerItem, Marker nativeItem)
{
@@ -151,6 +209,11 @@ protected override void OnUpdateIcon(Pin outerItem, Marker nativeItem)
{
nativeItem.Icon = outerItem?.Icon?.ToUIImage();
}
+
+ protected override void OnUpdateIsDraggable(Pin outerItem, Marker nativeItem)
+ {
+ nativeItem.Draggable = outerItem?.IsDraggable ?? false;
+ }
}
}
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/MapRenderer.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/MapRenderer.cs
index 25e0cf4f..d8dd42bd 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/MapRenderer.cs
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/MapRenderer.cs
@@ -7,6 +7,7 @@
using Xamarin.Forms.GoogleMaps.Internals;
using Xamarin.Forms.GoogleMaps.Logics.iOS;
using Xamarin.Forms.GoogleMaps.Logics;
+using Xamarin.Forms.GoogleMaps.iOS.Extensions;
namespace Xamarin.Forms.GoogleMaps.iOS
{
@@ -53,6 +54,8 @@ protected override void Dispose(bool disposing)
logic.Unregister(NativeMap, Map);
var mkMapView = (MapView)Control;
+ mkMapView.CoordinateLongPressed -= CoordinateLongPressed;
+ mkMapView.CoordinateTapped -= CoordinateTapped;
mkMapView.CameraPositionChanged -= CameraPositionChanged;
}
@@ -79,6 +82,8 @@ protected override void OnElementChanged(ElementChangedEventArgs e)
SetNativeControl(new MapView(RectangleF.Empty));
var mkMapView = (MapView)Control;
mkMapView.CameraPositionChanged += CameraPositionChanged;
+ mkMapView.CoordinateTapped += CoordinateTapped;
+ mkMapView.CoordinateLongPressed += CoordinateLongPressed;
}
MessagingCenter.Subscribe
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.nuspec b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.nuspec
index 7e12d730..9cafb6ef 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.nuspec
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.nuspec
@@ -3,8 +3,15 @@
Xamarin.Forms.GoogleMaps
Xamarin.Forms.GoogleMaps
- 1.4.1
+ 1.5.0
+# 1.5.0
+
+## New Features
+
+* #10 Moving pin by tap and hold (Android / iOS only)
+* #45 Support Map.MapClicked and MapLongClicked event (Android / iOS only)
+
# 1.4.1
## Bug Fixes
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Logics/DefaultPinLogic.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Logics/DefaultPinLogic.cs
index cb92ae42..a4af38eb 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Logics/DefaultPinLogic.cs
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Logics/DefaultPinLogic.cs
@@ -21,6 +21,7 @@ protected override void OnItemPropertyChanged(object sender, PropertyChangedEven
else if (e.PropertyName == Pin.PositionProperty.PropertyName) OnUpdatePosition(outerItem, nativeItem);
else if (e.PropertyName == Pin.TypeProperty.PropertyName) OnUpdateType(outerItem, nativeItem);
else if (e.PropertyName == Pin.IconProperty.PropertyName) OnUpdateIcon(outerItem, nativeItem);
+ else if (e.PropertyName == Pin.IsDraggableProperty.PropertyName) OnUpdateIsDraggable(outerItem, nativeItem);
}
protected abstract void OnUpdateAddress(Pin outerItem, TNative nativeItem);
@@ -32,6 +33,8 @@ protected override void OnItemPropertyChanged(object sender, PropertyChangedEven
protected abstract void OnUpdateType(Pin outerItem, TNative nativeItem);
protected abstract void OnUpdateIcon(Pin outerItem, TNative nativeItem);
+
+ protected abstract void OnUpdateIsDraggable(Pin outerItem, TNative nativeItem);
}
}
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Map.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Map.cs
index 30a4f859..86e6d548 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Map.cs
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Map.cs
@@ -28,6 +28,13 @@ public class Map : View, IEnumerable
public event EventHandler SelectedPinChanged;
+ public event EventHandler PinDragStart;
+ public event EventHandler PinDragEnd;
+ public event EventHandler PinDragging;
+
+ public event EventHandler MapClicked;
+ public event EventHandler MapLongClicked;
+
MapSpan _visibleRegion;
public Map(MapSpan region)
@@ -172,5 +179,30 @@ internal void SendSelectedPinChanged(Pin selectedPin)
{
SelectedPinChanged?.Invoke(this, new SelectedPinChangedEventArgs(selectedPin));
}
+
+ internal void SendPinDragStart(Pin pin)
+ {
+ PinDragStart?.Invoke(this, new PinDragEventArgs(pin));
+ }
+
+ internal void SendPinDragEnd(Pin pin)
+ {
+ PinDragEnd?.Invoke(this, new PinDragEventArgs(pin));
+ }
+
+ internal void SendPinDragging(Pin pin)
+ {
+ PinDragging?.Invoke(this, new PinDragEventArgs(pin));
+ }
+
+ internal void SendMapClicked(Position point)
+ {
+ MapClicked?.Invoke(this, new MapClickedEventArgs(point));
+ }
+
+ internal void SendMapLongClicked(Position point)
+ {
+ MapLongClicked?.Invoke(this, new MapLongClickedEventArgs(point));
+ }
}
}
\ No newline at end of file
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/MapClickedEventArgs.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/MapClickedEventArgs.cs
new file mode 100644
index 00000000..48bd5b2e
--- /dev/null
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/MapClickedEventArgs.cs
@@ -0,0 +1,14 @@
+using System;
+
+namespace Xamarin.Forms.GoogleMaps
+{
+ public class MapClickedEventArgs : EventArgs
+ {
+ public Position Point { get; }
+
+ internal MapClickedEventArgs(Position point)
+ {
+ this.Point = point;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/MapLongClickedEventArgs.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/MapLongClickedEventArgs.cs
new file mode 100644
index 00000000..d38a1ea1
--- /dev/null
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/MapLongClickedEventArgs.cs
@@ -0,0 +1,14 @@
+using System;
+
+namespace Xamarin.Forms.GoogleMaps
+{
+ public class MapLongClickedEventArgs : EventArgs
+ {
+ public Position Point { get; }
+
+ internal MapLongClickedEventArgs(Position point)
+ {
+ this.Point = point;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Pin.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Pin.cs
index a463e7d1..1f1eeab3 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Pin.cs
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Pin.cs
@@ -14,7 +14,7 @@ public sealed class Pin : BindableObject
public static readonly BindableProperty IconProperty = BindableProperty.Create("Icon", typeof(BitmapDescriptor), typeof(Pin), default(BitmapDescriptor));
- // introduced to store the unique id for Android markers
+ public static readonly BindableProperty IsDraggableProperty = BindableProperty.Create("IsDraggable", typeof(bool), typeof(Pin), false);
public string Label
{
@@ -46,6 +46,12 @@ public BitmapDescriptor Icon
set { SetValue(IconProperty, value); }
}
+ public bool IsDraggable
+ {
+ get { return (bool)GetValue(IsDraggableProperty); }
+ set { SetValue(IsDraggableProperty, value); }
+ }
+
public object Tag { get; set; }
public object NativeObject { get; internal set; }
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/PinDragEventArgs.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/PinDragEventArgs.cs
new file mode 100644
index 00000000..b736b18d
--- /dev/null
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/PinDragEventArgs.cs
@@ -0,0 +1,18 @@
+using System;
+namespace Xamarin.Forms.GoogleMaps
+{
+ public class PinDragEventArgs : EventArgs
+ {
+ public Pin Pin
+ {
+ get;
+ private set;
+ }
+
+ internal PinDragEventArgs(Pin pin)
+ {
+ this.Pin = pin;
+ }
+ }
+}
+
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Properties/GlobalAssemblyInfo.cs b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Properties/GlobalAssemblyInfo.cs
index 740e2eca..d0f9feb9 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Properties/GlobalAssemblyInfo.cs
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Properties/GlobalAssemblyInfo.cs
@@ -4,5 +4,5 @@
[assembly: AssemblyProduct("Xamarin.Forms.GoogleMaps")]
[assembly: AssemblyCopyright("Copyright © amay077. 2016")]
[assembly: AssemblyTrademark("")]
-[assembly: AssemblyVersion("1.4.1.0")]
-[assembly: AssemblyFileVersion("1.4.1.0")]
\ No newline at end of file
+[assembly: AssemblyVersion("1.5.0.0")]
+[assembly: AssemblyFileVersion("1.5.0.0")]
\ No newline at end of file
diff --git a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.csproj b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.csproj
index a4f01a51..522efb2c 100644
--- a/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.csproj
+++ b/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.csproj
@@ -54,6 +54,9 @@
+
+
+