Google Maps Android API utility library support

Hi,

I want make use of Google map maptag clustering which is part of Google Maps Android API utility library. I'm current make use of Google Play service from component store. Is there any chance that the utility library will be supported in near future or is there an alternative?

/OFK

Best Answers

«1

Answers

  • OFKOFK USMember ✭✭

    What will be the preferred way to include this library in Mono. JNI, binding etc.?

    https://developers.google.com/maps/documentation/android/utility/setup

  • g0ld2kg0ld2k USUniversity

    @OFK did you end up getting the Google Maps Android API Utility Library to work? I am looking at using this to do heat maps.

  • OFKOFK USMember ✭✭

    Hi,

    I have a bit progress but I have not achieved target yet. You can follow this bugzilla

    https://bugzilla.xamarin.com/show_bug.cgi?id=18154

    I have get rid of lot of missing class warnings from Jar2Xml. But I think that there is a limitation within Xamarin to support biinding to generics :-(

    Started new thread . You can follow this here

    http://forums.xamarin.com/discussion/14696/java-binding-to-a-generic-class-google-map-utility-limitations#latest.

  • OFKOFK USMember ✭✭
  • OFKOFK USMember ✭✭

    Thank You I'll try it out:-)

  • OFKOFK USMember ✭✭

    To Øystein Heimark,

    Could You pleas upload a sample project

  • OFKOFK USMember ✭✭

    Nice :-)

  • OFKOFK USMember ✭✭

    Thanks!

  • OFKOFK USMember ✭✭

    Cannot compile. Dp I miss something

    Error 29 The type or namespace name 'Utils' does not exist in the namespace 'Android.Gms.Maps' (are you missing an assembly reference?) C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\MapsUtilityDemo\ClusterItem.cs 3 24 MapsUtilityDemo
    Error 30 The type or namespace name 'IClusterItem' could not be found (are you missing a using directive or an assembly reference?) C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\MapsUtilityDemo\ClusterItem.cs 7 47 MapsUtilityDemo
    Error 9 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_pressed_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_dark.xml 4 MapsUtilityDemo
    Error 10 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_disabled_focus_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_dark.xml 7 MapsUtilityDemo
    Error 11 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_focus_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_dark.xml 11 MapsUtilityDemo
    Error 12 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_disabled_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_dark.xml 14 MapsUtilityDemo
    Error 13 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_normal_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_dark.xml 17 MapsUtilityDemo
    Error 14 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_pressed_light'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_light.xml 4 MapsUtilityDemo
    Error 15 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_disabled_focus_light'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_light.xml 7 MapsUtilityDemo
    Error 16 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_focus_light'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_light.xml 11 MapsUtilityDemo
    Error 17 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_disabled_light'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_light.xml 14 MapsUtilityDemo
    Error 18 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_icon_normal_light'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_icon_light.xml 17 MapsUtilityDemo
    Error 19 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_text_pressed_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_text_dark.xml 4 MapsUtilityDemo
    Error 20 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_text_disabled_focus_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_text_dark.xml 7 MapsUtilityDemo
    Error 21 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_text_focus_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_text_dark.xml 11 MapsUtilityDemo
    Error 22 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_text_disabled_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_text_dark.xml 14 MapsUtilityDemo
    Error 23 No resource found that matches the given name (at 'drawable' with value '@drawable/common_signin_btn_text_normal_dark'). C:\Users\olefa_000\Downloads\MapsUtilityDemo-master\MapsUtilityDemo-master\Components\googleplayservicesgingerbread-15.0.2\lib\android\15\content\google-play-services\libproject\google-play-services_lib\res\drawable\common_signin_btn_text_dark.xml 17 MapsUtilityDemo

    Regards OFK

  • OFKOFK USMember ✭✭

    Downloading unpacked version. "Only" get this problem

    Error 9 The type or namespace name 'Utils' does not exist in the namespace 'Android.Gms.Maps' (are you missing an assembly reference?) C:\Users\olefa_000\Documents\GitHub\MapsUtilityDemo\MapsUtilityDemo\ClusterItem.cs 3 24 MapsUtilityDemo
    Error 10 The type or namespace name 'IClusterItem' could not be found (are you missing a using directive or an assembly reference?) C:\Users\olefa_000\Documents\GitHub\MapsUtilityDemo\MapsUtilityDemo\ClusterItem.cs 7 47 MapsUtilityDemo

    /OFK

  • OFKOFK USMember ✭✭

    I came a bit further. Now I can build after some manual building process.

    Now I get this when running the App

    "mapsandlocationdemo.mapsutilityaddons.ClusterItem cannot be cast to com.google.maps.android.clustering.ClusterItem"

    casting from ClusterItem to Java object fails. Have You experienced similar behavior?

  • ysteinHeimarkysteinHeimark NOMember

    No, I have never seen anything like that. I just pulled the demo project fresh from git and tried to run it. Still working perfectly for me.

    I'm building it using Xamarin Studio on Mac, don't know if this makes a difference. Afraid I can't help you too much with this problem as I'm not seeing this error myself.

  • OFKOFK USMember ✭✭

    Obviously this makes a difference. I will continue searching. At least it is much better now.

    SW is not an exact science:-)

  • OFKOFK USMember ✭✭

    I'm now able to run a little test App'en with a number of markers. Unfortunately I'm only able to apply standard markers. I tried to add my own Icon resource and name. But it has no effect. Have You been able to customize Your markers?

    Doing something like this

    mClusterManager = new ClusterManager(this, _map);

    mClusterManager.AddItem(new Person(position(), "Walter", Resource.Drawable.p01001));

    /OFK

  • ysteinHeimarkysteinHeimark NOMember

    Yes, I achieved this by extending the DefaultClusterRenderer class. By overriding for instance the OnBeforeClusterItemRendered method you get access to the markerOptions used to draw the marker.

    Have a look at the demo classes provided with the Google Maps Utility project for more details on how to achieve this, in particular the CustomMarkerClusteringDemoActivity.

  • OFKOFK USMember ✭✭

    thanks. I will take a look.

  • OFKOFK USMember ✭✭

    Hmm, I'm get stucked in getting this worked. I don't get callback to OnBeforeClusterItemRendered for some reason.

    I only wan't to get access to the markeroption.

    I can't really see what's my problem. Do I miss something? Probably YES :-)

    See my sample

  • OFKOFK USMember ✭✭

    An example could be nice to see it work in C# implementation. I simply can't get work in Mono android
    public void OnBeforeClusterItemRendered(Person person, MarkerOptions markerOptions)

    Is never called when ClusterItem is going to be showed at the map

  • ysteinHeimarkysteinHeimark NOMember

    The only thing I can spot is that you should use protected override void OnBeforeClusterItemRendered instead of public void OnBeforeClusterItemRendered. The same goes for the ShouldRenderAsCluster method. Also the first parameter of the OnBeforeClusterItemRendered method should be of type Java.Lang.Object instead of the Person class. This is because the override method expects it, you can cast it to a Person object once inside the method. Maybe this will help?

  • OFKOFK USMember ✭✭

    Thanks. Now I succeed. I had tried with overriding but without Java.Lang.Object

    This was indeed the problem

  • outluchoutluch USMember

    Excuse me, i have the same problem: ClusterItem' could not be found
    How did you solve this?

  • OFKOFK USMember ✭✭
  • outluchoutluch USMember

    Whoops!
    You don't have permission to do that.

  • machinezonemachinezone USMember

    @ysteinHeimark Thanks for the post and uploaded demo. Compiles and runs fine for me.

  • JamesMundyJamesMundy GBMember

    At Foundbite we had a bit of trouble getting the library to build and acknowledge the ClusterManager class, so we forked the repo and updated it with the latest code. It can be found here: https://github.com/jamesmundy/MapsUtilityDemo
    Hope it is useful to otherse.

  • NinineaNininea USUniversity ✭✭✭
    edited August 2015

    Hey Guys,

    At first this post really helped me ^_^

    I have one question regarding this topic. I need to show info window of marker on listview item click, So if marker is not rendered (it it clustered) I'm not able to find it :

    Marker marker = _clusterManager.MarkerCollection.Markers.FirstOrDefault (x => x.Snippet == item.MerchantId);

    marker is null;

    I try to zoom map on item position and after that call OnMarkerClick

    ZoomMap (item.Longitude.Value, item.Latitude.Value, true);
                Marker marker = _clusterManager.MarkerCollection.Markers.FirstOrDefault (x => x.Snippet == item.MerchantId);
    
    
                if (marker != null) {
                    OnMarkerClick (marker);
                }
    

    But some cases marker still is null, because camera update is not completed, or not zoomed enough

    Can you suggest me better solution , please?

  • NinineaNininea USUniversity ✭✭✭
    edited October 2015

    I have updated OS to api level 23 and got unexpected problem , custome icons is not rendering for every cluster item :
    here is my renderer:

    protected override void OnBeforeClusterItemRendered (Java.Lang.Object obj, MarkerOptions markerOptions)
            {
                base.OnBeforeClusterItemRendered (obj, markerOptions);
                try {
                    ClusterItem item = obj as ClusterItem;
                    markerOptions.InvokeIcon (BitmapDescriptorFactory.FromBitmap (item.Icon));
                    markerOptions.SetSnippet (item.MerchantId);
                } catch (System.Exception ex) {
                }
            }
    

    I'm getting icon from drawer:

    `   Bitmap icon = DrawableToBitmap (marker);`
    
            public static Bitmap DrawableToBitmap (Drawable drawable)
                {
                    if (drawable is BitmapDrawable) {
                        return ((BitmapDrawable)drawable).Bitmap;
                    }
    
                    Bitmap bitmap = Bitmap.CreateBitmap (drawable.IntrinsicWidth, drawable.IntrinsicHeight, Bitmap.Config.Argb8888);
                    Canvas canvas = new Canvas (bitmap);
                    drawable.SetBounds (0, 0, canvas.Width, canvas.Height);
                    drawable.Draw (canvas);
    
                    return bitmap;
                }
    

    during zoom map gets not interactive , application stops working and gets the exception:

    Java.Lang.OutOfMemoryError:
    Could not allocate JNI Env

    anyone has the same issue?

    if I remove this line :
    markerOptions.InvokeIcon (BitmapDescriptorFactory.FromBitmap (item.Icon));
    application works normally

  • NinineaNininea USUniversity ✭✭✭

    also for some markers it doesn't renders custom icons, here is how does my screen look :

  • SafakktemSafakktem USMember ✭✭

    Is there any resolution google maps clustering both android and ios?

  • AlexSAlexS USUniversity ✭✭✭

    You have to do it for each platform.

  • DilipPDilipP INMember

    Hi @AlexS
    I am new to android xamarin development. I have added maps and markers successfully but not able to get the marker clustering. I have visited few websites but i am only getting the source code.

    Can you please let me know the steps to implement this. Like what dll file i need to give reference. Few initial steps will be helpful.

    Thanks!

  • RobertoManganoRobertoMangano CHMember ✭✭

    @AlexS said:
    You have to do it for each platform.

    I can't find any implementation of this, nor yours nor anyone's elses that works with the current configuration

    (Gmaps 29.0.02, support v4 24.2.1)

    Your beta alex, requires beta packages which are not compatible with my config.

    Also, @JamesMundy solution is not working properly

    Does anyone have a working package/solution for clustering on droid? And updated?

  • AlexSAlexS USUniversity ✭✭✭

    @RobertoMangano, then, since you need custom configuration, you have to make a fork of the repo https://github.com/alexsorokoletov/Xamarin.Android.Maps.Utils and use Google.Maps package and Support V4 package that you specifically need and use it in the app.

    I understand this is a limitation of packaging utility as a NuGet (you can't package it for any configuration).
    However, alternative would be just upgrading your app to the latest Google.Maps and Support packages.

  • RobertoManganoRobertoMangano CHMember ✭✭

    My Solution:

    My projects are referencing Xamarin.Maps 29.0.0.2

    So i downloaded @AlexS solution, imported map-utils 0.4.3 found here

    https://mvnrepository.com/artifact/com.google.maps.android/android-maps-utils/0.4.3

    i imported it in his proj, built it as LibraryProjZip, referenced the project in my project which contains the GoogleMap, and used the code to reference the Clustermanager.

    Now everything works.

    Cheers

  • VivekNigamVivekNigam USMember ✭✭

    @OFK said:
    I came a bit further. Now I can build after some manual building process.

    Now I get this when running the App

    "mapsandlocationdemo.mapsutilityaddons.ClusterItem cannot be cast to com.google.maps.android.clustering.ClusterItem"

    casting from ClusterItem to Java object fails. Have You experienced similar behavior?

    @ysteinHeimark said:
    Hi,

    After a lot of work I was finally able to get this library working.

    Following the description from your bug report on Bugzilla I was able to build a bindings library with the Google Maps Utility. One small difference was that I added the Google Play Services component to my bindings library instead of creating a separate bindings library for this.

    When building my bindings library I was getting the same error as you were experiencing with the DefaultClusterRenderer class(missing class com.google.maps.android.R). The only difference for me was that the DefaultClusterRenderer class actually was included in the resulting dll file. However when I tried to use this class in my app it crashed with a unknown class reference exception as it did not recognise the com.android.maps.R class. Also I had to remove the com.google.maps.android.heatmaps package entirely, excluding it with the Metadata file, as this was causing an error(I’m not planning to use this feature so I decided to just remove it).

    After spending some time searching for similar problems, I came over this blog post(look at the first comment). Following the instructions here I tried to remove all the references to the static R class in the original Google Maps Utility library with getContext().getResources().getIdentifier(name, type, packageName) instead. For instance, R.style.ClusterIcon_TextAppearance was replaced with context.getResources().getIdentifier("ClusterIcon_TextAppearance", "style", context.getPackageName()).

    Searching through the library I identified two classes that referenced the static R class, the DefaultClusterRenderer class and the IconGenerator class. Having changed all these references to follow the format above I rebuilt the project and imported the new .jar file in my bindings project. I was now no longer getting the missing class warnings from the jar2xml process.

    Running the app again I received a new error, the project was not able to find some resource referenced by the Google Maps Utility library. To solve this I had to include the library as a zip file(with the bin and res folders) instead of the jar file. This ensures that all the resources of the utility library is included in the bindings project as well. Once I had done this my app was finally running and the clustering feature is now working perfectly in my app :)

    Hi.. i am trying to implement the clustering in my project and the project contain the push notification also. when i tried to put some dll for the push notification it is throwing the error."Attribute "mapType" already defined with incompatible format" and sometimes "The "ResolveLibraryProjectImports" task failed unexpectedly." error is giving. i have deleted the obj and bin folder but still getting the error. please help me so that i can implement the push notification and the map clustering also. its very urgent. Thanks

  • gustaveracostagustaveracosta GBMember ✭✭

    Just download from Nuget:

    Xamarin.Android.Maps.Utils

    GoogleMapsUtils.iOS

«1
Sign In or Register to comment.