Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to support both google map apis (v1 and v2)?

What is the best way to support both android map apis in my application ?

Google released the android google map api v2 while the v1 is still around (and works better for older phones).

So far, I see two scenarii.

1) Two apks : one apk for each api

I could use the multiple apk feature available in google play.

  • How would I do the distinction on google play ? On the opengl support ?

This scenario means that each time I want to build my project, I have to copy/paste some files, update others which could be cumbersome.

Unless I use a tailored build process (Using ant or maven).

  • Any recommendation on that matter ?

2) One apk

That one could be achieved using if/else statements, including in the manifest file the declaration for both the apis.

  • Has anyone ever tried this ?

Note : Google maps for older phones

First, the new v2 api is vector based which is heavier on the CPU/GPU (the v1 api used bitmap tiles).

Second, the new v2 api requires opengl 2.0. Which is said to be supported in all Android device running froyo or later. Unfortunately, this is not true.

For example, a venerable HTC magic running gingerbread (on a custom rom) is not recognized by the google play/market to support opengl 2.0.

And maybe there are more of them...

like image 969
Name is carl Avatar asked Dec 22 '12 00:12

Name is carl


2 Answers

That one could be achieved using if/else statements, including in the manifest file the declaration for both the apis.

Well, you cannot have "if/else statements" in the manifest.

There are basically three scenarios from my standpoint:

  1. The device does not have OpenGL ES 2.0 or higher
  2. The device does have OpenGL ES 2.0 or higher but does not presently have the Google Play Services (possibly because it does not have the Play Store)
  3. The device has OpenGL ES 2.0 or higher and has Google Play Services

As you note in your comment on another answer, my Scenario #1 cannot co-exist with the other two, simply because you must have the <uses-feature> element calling for OpenGL ES 2.0. And, since the Play Store does not support multiple APK files based on OpenGL ES API level, you cannot support Scenario #1 and the other two scenarios at the same time for the same Play Store listing. You would have to have two completely separate apps in the Play Store: one that only uses Maps V1 that works on all Android devices and one that uses Maps V2 (falling back to something else, like Maps V1, for my Scenario #2) that works on OpenGL ES 2.0+ devices.

Also, bear in mind that Maps V1 API keys are not going to be available after 3 March 2013. Doing Maps V1 development after that point gets increasingly risky, as you have no way of getting fresh API keys should something go wrong with your development environment.

Basically, what this means is that developing apps dependent upon Google Maps sucks in new and interesting ways, compared to the way it sucked before. Even if you say that you will abandon Maps V1 outright, there are the devices that fall into my Scenario #2. Hopefully, there are not that many, though there definitely are some (such as an HTC EVO 3G sitting near me). There should be no such devices running Android 3.0 and higher -- I'm pretty sure that OpenGL ES 2.0 was a hard-and-fast requirement for Android 3.0, and the Play Store should be on all of those devices (and, hence, Google Play Services should be available for all of them).

Frankly, the best answer for some developers will be to dump Google entirely with respect to maps and use OpenStreetMap or something else that has greater stability, if they want to support Android 1.x/2.x devices.

like image 122
CommonsWare Avatar answered Sep 28 '22 10:09

CommonsWare


The OpenGL 2.0 requirement is more from a support perspective. I've found Google Maps Android API v2 to be running well on an HTC Wildfire, for instance!

Short answer to your question: don't do it. Pick one, stick to it.

Medium answer: don't do it. Pick one, stick to it. If you really need some of the old features and cannot recreate them in new v2 API then that suggests you should stick with v1.

If its just a few old 2.1 devices you worry about - don't worry, people really shouldn't be using 2.1 any more as its got security flaws, you're doing a public service by not supporting it (encouraging users to update their phones...which is a little sad from an environmentally-friendly perspective but the manufacturers and carriers already forced that problem so don't let it be yours!).

If its just a few non-openGL 2.0 devices you worry about, then ommit the feature requirement, though at the risk of some crazy problems occurring down the track. Probably best to provide a clear warning that problems may occurr on non-openGL 2.0 devices.

If you really, really must support both versions then just do it. Not many people would be crazy enough to do the same that you will find a 'best-practices' list eventuating. You'd probably want to use one of the v1 API MapFragment solutions though, as it happens I wrote one: https://github.com/coreform/android-tandemactivities

like image 39
straya Avatar answered Sep 28 '22 10:09

straya