Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voting: Map Marker Clustering #123

Closed
declandowling opened this issue Nov 24, 2016 · 97 comments
Closed

Voting: Map Marker Clustering #123

declandowling opened this issue Nov 24, 2016 · 97 comments

Comments

@declandowling
Copy link

declandowling commented Nov 24, 2016

If you want to this feature then post 👍 to below.

Suggestion

Implement google maps clustering utility for Android & iOS.

Android:
https://developers.google.com/maps/documentation/android-api/utility/marker-clustering

iOS:
https://developers.google.com/maps/documentation/ios-sdk/utility/marker-clustering

@amay077
Copy link
Owner

amay077 commented Dec 3, 2016

Goog idea!
Is there someone who can port to C#?

@jaykannan
Copy link

@amay077 amay077 changed the title Suggestion - Map Marker Clustering Voting: Map Marker Clustering Feb 8, 2017
@claudiocleberson
Copy link

I stabled upon that repo, maybe that can help a bit with te Android side
https://github.com/oystehei/MapsUtilityDemo/tree/master/MapsUtilityDemo

@YahavGB
Copy link

YahavGB commented Mar 25, 2017

Someone found a way to integrate it? I can't find a way to translate Pin into POIItem.

@YahavGB
Copy link

YahavGB commented Mar 28, 2017

Okay, I'm working on a port to the clustering feature. I'll post it soon :).

@amay077
Copy link
Owner

amay077 commented Mar 29, 2017

I found some repos.

But these are "Binding" projects.
I hope "PORT" from java to C# because core logic is same as Android and iOS.

@YahavGB
Copy link

YahavGB commented Mar 29, 2017

@amay077 yes, I mean a complete port to the clustering feature from Xamarin iOS and Xamarin Android to Xamarin Forms. This port is based on a fork of this project and its API, obviously.

@amay077
Copy link
Owner

amay077 commented Mar 29, 2017

The original sources are here:

Thanks @YahavGB,
I am waiting expectantly.

@YahavGB
Copy link

YahavGB commented Apr 21, 2017

@amay077 as promised, I've implemented a unified API for clustering (a basic one, though).
The API supports marker clustering, custom markers, custom clusters and buckets. It currently works on iOS and Android.

Please check my forked repository and check it so I can submit a pull request - https://github.com/YahavGB/Xamarin.Forms.GoogleMaps.

Sample code:

        for (var i = 0; i <= ClusterItemsCount; i++)
        {
            var lat = this._currentPosition.Latitude + Extent * GetRandomNumber(-1.0, 1.0);
            var lng = this._currentPosition.Longitude + Extent * GetRandomNumber(-1.0, 1.0);

            this.Map.ClusteredPins.Add(new Pin()
            {
                Position = new Position(lat, lng),
                Label = $"Item {i}",
                Icon = BitmapDescriptorFactory.FromBundle("pin_red.png")
            });
        }

Note the usage of ClusteredPins instead of Pins. Using that approach one can mix between standard pins (which won't be clustered) and clustered pins. For advance options, see ClusterOptions.cs.

Hope it'll help 👍 !

@amay077 amay077 mentioned this issue Apr 25, 2017
3 tasks
@mpgalo
Copy link

mpgalo commented Apr 28, 2017

Why don't incorporate that resource on the Xamarin.Forms.GoogleMaps package?

@YahavGB
Copy link

YahavGB commented Apr 28, 2017

@mpghelli The clustering feature has been implemented as a fork of this repository. When it'll get general approval I'll submit it as a pull request.
Meanwhile you can use my forked repository.

@amay077
Copy link
Owner

amay077 commented Apr 28, 2017

I have a plan to contains Marker clustering in Xamarin.Forms.GoogleMaps.
But sorry I can not try @YahavGB 's implementation yet.

@mpgalo
Copy link

mpgalo commented Apr 28, 2017

Is there anyway to get forked repository by nuget? Im getting problems to compile Android project. Lacks Xamarin.Forms.GoogleMaps.Android.Utils reference.

@YahavGB
Copy link

YahavGB commented Apr 28, 2017 via email

@mpgalo
Copy link

mpgalo commented Apr 28, 2017

Yes. I Would like. I will be thankfull if you can do that. :)

@mpgalo
Copy link

mpgalo commented Apr 28, 2017

I did it compile and generated the Dlls. I've Added Xamarin.Forms.GoogleMaps dll reference on portable class library and Xamarin.Forms.GoogleMaps.Android too on Android project, but when i compile my project it throw some exceptions. Seems it lacks some packages of Android SDK itself:

Severity Code Description Project File Line Suppression State
Error error: package com.google.maps.android.clustering.ClusterManager does not exist
com.google.maps.android.clustering.ClusterManager.OnClusterClickListener MRV.Terrenos.Mobile.Droid C:\Projetos\MRV TERRENOS\src\v1\dev\MRVTerrenos\MRV.Terrenos.Mobile\MRV.Terrenos.Mobile.Droid\obj\Debug\android\src\mono\com\google\maps\android\clustering\ClusterManager_OnClusterClickListenerImplementor.java

Seems im using the same android librarys that example project.
Do I have to add any other references?

@YahavGB
Copy link

YahavGB commented Apr 28, 2017

@mpghelli I've uploaded the libraries to my Drive, you can grab them here: https://drive.google.com/drive/folders/0B02ufEMX6wJ7WmxFMHh2bHFXdUE?usp=sharing

How to integrate the libraries:

The shared project
Instead of adding Xamarin.Forms.GoogleMaps from nuget, add a reference to the local assembly you've downloaded from Drive.
shared

Android
Instead of adding the nuget package, add a reference to these DLLs:

  • Xamarin.Forms.GoogleMaps.dll
  • Xamarin.Forms.GoogleMaps.Android.dll
  • GoogleMapsUtility.dll
    In addition, you do need to add a reference to Google Play Maps package, so you can do it using NuGet (simply install Xamarin.GooglePlayServices.Maps).

Android

iOS
Instead of adding the nuget package, add a reference to these DLLs:

  • Xamarin.Forms.GoogleMaps.dll
  • Xamarin.Forms.GoogleMaps.iOS.dll
  • GoogleMapsUtility.dll
    In addition, you do need to add a reference to Google Play Maps package, so you can do it using NuGet (simply install Xamarin.Google.iOS.Maps).

iOS

@YahavGB
Copy link

YahavGB commented Apr 28, 2017

@mpghelli It seems like it doesn't appear on the iOS image, but just to clarify, in the iOS project you should reference GoogleMapsUtils.iOS.dll.

@mpgalo
Copy link

mpgalo commented Apr 28, 2017

Thank you very much. I will try that and keep you informed. :)

@mpgalo
Copy link

mpgalo commented Apr 28, 2017

It Works!!!

But i don't understand some behaviors. Some times it has just 5 pins, but group in a circle wrote with 10+. Is that the correct behavior?

Another question is if is possible to group the Pins with the same Icone first?

Thanks Again.

@YahavGB
Copy link

YahavGB commented Apr 28, 2017 via email

@mpgalo
Copy link

mpgalo commented Apr 28, 2017

I have a collection that i
loop through and create a clustered Pin for each one. I've tested only in android 5.0 until now.

`
foreach (var terreno in terrenos)
{
var pinCoord = GetPositionByCoordinate(terreno.Coordenadas.Split('|').First());

           var pin = CreateLandPin(
               Terreno,
               terreno.Id,
               terreno.Nome,
               terreno.Logradouro,
               pinCoord,
               terreno.Cor);

              var customPin = new TerrenosPin(terreno, pin);

            this.mapTerrenos.ClusteredPins.Add(new Pin()
            {
                Position = customPin.MapPinPosition,
                Label = customPin.MapPinLabel,
                Icon = customPin.MapPin.Icon
            });         
        }

`

Like i said, it groups less then 10 itens in a 10+ grouped pin, but when i clicked in that grouped pin it show the correct number of pins grouped inside.

Thank You

@mpgalo
Copy link

mpgalo commented Apr 28, 2017

The CameraChanged event stoped worked using this dll version too.

Maybe it was overriden inside the dll to make the grouping?

Thanks

@poseydonfba
Copy link

The icon shows grouped 10+, when I click on it, it shows 5 items in cluster, ... any ideas?

image

@leaguefun
Copy link

👍

1 similar comment
@mpgalo
Copy link

mpgalo commented May 23, 2017

👍

@leemarthers
Copy link

@mierzynskim, looks like we are running into a gref limit in android.

@stavroaudi
Copy link

@mierzynskim Sorry I'm quite new to this. If I fork from your solution on visual studio, how can I create DLL files for Android and iOS? I know for the shared project I can make the solution as a nuget package. Otherwise if you can send me the precompiled DLLs that would be great. I can then test and let you know if there is a significant performance upgrade

@chrisgate
Copy link

why dll when u have nuget https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/

@mierzynskim
Copy link
Contributor

@leemarthers Yeah, I think there's nothing more we can do with it 😞. For those of you who struggles with huge amount of markers here's a possible solution.. I haven't got time to test it myself but limiting amount of markers to a visible region seems to be good idea.

@amay077 I'd love to hear your thoughts about implementing the extension. I'm not sure what structure you expect but I offer my help to implement it.

@stavroaudi
Copy link

@chrisgate The nuget doesn't include clustering.

@vishaljani23
Copy link

vishaljani23 commented Aug 28, 2018

@mierzynskim can you pls share latest compiled dlls for both Android and iOS as Android Utils is not building in my system... Thanks..

@carlosmacmar
Copy link

Hey @mierzynskim ! I've been trying to check your clustering example but I'm not able to. There is an error in Xamarin.Forms.GoogleMaps.Android\Logics\ClusterLogic.cs. In this line:
this.NativeMap.SetOnCameraIdleListener(this._clusterManager);

I get the error:

Argument 1: cannot convert from 'Com.Google.Maps.Android.Clustering.ClusterManager' to 'Android.Gms.Maps.GoogleMap.IOnCameraIdleListener' Xamarin.Forms.GoogleMaps.Android

Any idea about what could be happening? Thanks!!

@leemarthers
Copy link

@mierzynskim I just noticed another issue in testing in android. Each pin is being counted as two or three when clustered. I have 37 pins but I am getting a bucket of 50+ and a bucket of 10+. When I zoom in I can see a bucket of 6 break into 2 pins.

Any thoughts?

@Ajin001
Copy link

Ajin001 commented Nov 2, 2018

Latest Xamarin.Forms.GoogleMaps package not providing clustering feature in Xamarin forms.
Is there any alternative way to implement clustering in Xamarin form maps?
Thanks in Advance

@NamCkiku
Copy link

I'm not update data pin marker when use ClursterPin. How to fix it?

@darkovuj
Copy link

darkovuj commented Jan 2, 2019

How to cluster less then 5 pins? If I change ClusterItemsCount to 3 in ClusterPage.xaml.cs (in XFGoogleMapSample) it does not cluster at all. Can you cluster less then 5 pins?

edit:
I should ask this question 12h before, since I found solution 5sec after posting comment :(

answer is: set MinClusterSize in XamarinClusterRenderer.cs (Xamarin.Forms.GoogleMaps.Android.Logics.Cluster.XamarinClusterRenderer)
for example in ctor add:
this.MinClusterSize = 2;

@bryan2306
Copy link

bryan2306 commented Jan 16, 2019

Bonjour , je souhaite faire sur ma map en c# en UWP regrouper mes icons lorsqu'ils sont tous au même en droit, cependant je n'ai trouver aucun code en c# qui me permet de m'aider a realiser cette tache
pouvez vous m'aider svp après de nombreuses recherche cela ne me mène a rien
je vous remercie

@philipogorman
Copy link

hi @mierzynskim I'm trying the clustering fork you made, thanks for the work! I see the issue with the rendering time with a large amount of map object 10k+, but I think it will still be very useful in a lot of cases. I'm looking through the code now, it might take a while to understand, but if you want any assistance let me know.

@gabrielbunselmeyer
Copy link

Any more work being done on this? I think it's evident it'd be quite useful.

@mierzynskim
Copy link
Contributor

Hey! I finally had some time and created extension library for Xamarin.Forms.GoogleMaps https://github.com/mierzynskim/Xamarin.Forms.GoogleMaps.Clustering. It currently depends on my custom fork but I'm planning to create PR that introduces my changes to the core library and create a nuget package. So stayed tuned and I'd appreciate any feedback 😄

@gabrielbunselmeyer
Copy link

That is some great work! Thanks so much.

@mierzynskim
Copy link
Contributor

and until there isn't official nuget package, you can find precompiled dlls here https://drive.google.com/open?id=1WamukWgSSR4NKdev2Wz-o2OuDePADsNy

@gabrielbunselmeyer
Copy link

@mierzynskim Clustering is working fine, though now clicking on a pin shows the default InfoWindow again. The approach of setting "e.Pin.Label" and "e.Pin.Address" to null on the method treating the PinClicked event doesn't seem to work anymore. Any thoughts?

@mierzynskim
Copy link
Contributor

@gabrielbunselmeyer I'm not sure if I got what you mean by that. Would you mind submitting an issue with more detailed explanation? Code samples would also be useful.

@gnout
Copy link

gnout commented Feb 7, 2019

@amay077 Are there any plans to integrate clustering to the GoogleMaps NuGet Package?

@NirmalSubedi17
Copy link

NirmalSubedi17 commented Feb 8, 2019

@mierzynskim @gabrielbunselmeyer encountered the problem like I did today. If we do not set "Label" property of Pin.
Map.PinClicked event always returns the First Clustered pin as PinClickedEventArgs. It will not return the one that was clicked.

@zs-dima
Copy link

zs-dima commented Feb 9, 2019

@mierzynskim Amazing, Thanks a lot!
Some time default pin icons displayed instead of one had been set, easy to reproduce:
mierzynskim/Xamarin.Forms.GoogleMaps.Clustering#7

@NirmalSubedi17
Copy link

@mierzynskim I faced Icon Changing issue. Icon is not changing when we assign new icon when somebody clicks on pin.
Here is the snippet:

map.PinClicked += (object sender, PinClickedEventArgs e) =>
            {
                if (e.Pin != null && e.Pin.Tag != null)
                {
                    if (activePin != null)
                        activePin.Icon = BitmapDescriptorFactory.FromBundle("mapRedPin");

                    var clickedPin = map.ClusteredPins.FirstOrDefault(f => f.Tag.Equals(e.Pin.Tag));
                    clickedPin.Icon= BitmapDescriptorFactory.FromBundle("mapBluePin");
                    activePin = clickedPin;
                }
            };

I tried same with E.Pin as well with no luck then I tried to Find the Pin from ClusteredPins.

Thank you,
Nirmal Subedi

@mierzynskim
Copy link
Contributor

@NirmalSubedi17 Thanks for pointing it out. Since Clustering became standalone repo, please create an issue on https://github.com/mierzynskim/Xamarin.Forms.GoogleMaps.Clustering. Please also note that I'm not going to answer questions regarding issues in this thread anymore.

@amay077
Copy link
Owner

amay077 commented Mar 30, 2019

I support @NirmalSubedi17 's Xamarin.Forms.GoogleMaps.Clustering. (#123 (comment))

I don't add marker clustering in Xamarin.Forms.GoogleMaps.
If you want marker clustering, please use Xamarin.Forms.GoogleMaps.Clustering or you implement it.

@AlonRom
Copy link

AlonRom commented Dec 1, 2020

@amay077 as promised, I've implemented a unified API for clustering (a basic one, though).
The API supports marker clustering, custom markers, custom clusters and buckets. It currently works on iOS and Android.

Please check my forked repository and check it so I can submit a pull request - https://github.com/YahavGB/Xamarin.Forms.GoogleMaps.

Sample code:

        for (var i = 0; i <= ClusterItemsCount; i++)
        {
            var lat = this._currentPosition.Latitude + Extent * GetRandomNumber(-1.0, 1.0);
            var lng = this._currentPosition.Longitude + Extent * GetRandomNumber(-1.0, 1.0);

            this.Map.ClusteredPins.Add(new Pin()
            {
                Position = new Position(lat, lng),
                Label = $"Item {i}",
                Icon = BitmapDescriptorFactory.FromBundle("pin_red.png")
            });
        }

Note the usage of ClusteredPins instead of Pins. Using that approach one can mix between standard pins (which won't be clustered) and clustered pins. For advance options, see ClusterOptions.cs.

Hope it'll help 👍 !

@YahavGB is there a way to distinguish between binding to the clustered itemsource and the regular pins itemsource without overriding the Xamarin.Forms.GoogleMaps source code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests