3
votes

I'm trying to get the Google Maps v2 API working with MvvmCross v2 (vNext) and have run into some problems.

The example that I have for using Google Maps with MvvmCross has a view that inherits from MvxBindingMapActivityView. The trouble is that this uses MapView from the Google Maps v1 API, but this API is deprecated and Google is no longer issuing license keys.

I have some code adapted from the Xamarin Google Maps v2 example which works great:

https://github.com/xamarin/monodroid-samples/tree/master/MapsAndLocationDemo_v2

But I don't understand how to get this working with MvvmCross v2. It also uses fragments, and I'm not sure whether this is supported with the current version of MvvmCross?

I can get my Google Maps v2 Activity working fine outside of the MvvmCross framework by firing off an Intent from a MvvmCross view, and this is definitely an option, but I was wondering if there was any support inside MvvmCross for Google Maps v2 or whether the hackery involved would be more trouble than it's worth.

Thanks!

Matthew

1

1 Answers

0
votes

The maps code in v1 (master) and v2 (vNext) MvvmCross both relied on the Google Maps v1 API - so is no longer an option for new apps.

Meanwhile, master and vNext were also firmly rooted in Android v1 and v2 - so don't contain any fragment support.

So your analysis of the situation is right.


Some options for developing with Google Maps v2 are:

  1. Add a non-Mvvm Activity within your app for the page/tab that needs the new style map.

  2. Try to implement an ExFragmentActivity - with or without data-binding support.

    To do this you first need to inherit from Android's FragmentActivity class and then you need to provide some additional methods and properties. More on this in Insert a Monogame view inside MvvmCross monodroid Activity.

    There's a lot of cut and paste in doing this, but I think it should be trivial to get an ExFragmentActivity working to a non data-binding level.

    To go further - to get data-binding working as well - you may then find that you need to adjust the binding/inflation code - the code around LayoutInflater. The way that the FragmentManager hooks into the parent FragmentActivity may need to be adjusted. Sorry I don't have more details on how to do this - I think this is where hackery and some experimentation might be involved.

  3. v3 will have full Fragment support - so switching to v3 (when it ships) and using fragments is one option for future support. However, the changes from older versions to v3 are quite large - so doing this may not be an option right now - depends where you are in your project.