2014/08/08

Static map library


Have you ever used Google Static Map API? Let me introduce static-map android library based on this great service.

This is open source software, so you are welcome to get source code at github project page. Also, feel free to create issues regarding bugs of improvement suggestions. I can't promise I'll resolve them asap, but I'll try to find time for that =)


Google Static Maps service


Google Static Map API documentation is available here. Please, read it first if you are not familiar with service requirements and differences. Also, you can find usage limits and support there.



Supported features:
  • Basic map params: zoom, scale, image size
  • Secure access (https protocol support)
  • Location setting (geo position, address)
  • Map types (roads, satellite, etc)
  • Markers (without custom icon)

Unfortunately, a lot of Google Static Maps service features are not supported by library yet. Such as paths, maps styles, image formats, viewports, etc. Well, these features may be implemented in next versions of library. But you are always welcome to fork project at github and implement you own needs. If so, please, make pull request and help this little project to grow.


Usage


The library available at maven central repository. You can use Gradle,please resource to generate dependency definition. Or just type:

dependencies {
    compile 'com.github.d-max:static-map:0.1.3@aar'
}

There are javadoc and sources packages available to download from maven repo. Please, read more about dependencies classifiers at gradle userguide page.

Use Config class to set map generation basic params. Example:

Config config = new Config();
config.setImageSize(200, 300)
      .setZoom(10)
      .setAddress("Kyiv");

StaticMap class contais two static methods for map generation. To get map image synchronously use like this:

Bitmap img;
try {
    img = StaticMap.requestMapImage(context, config);
} catch (StaticMapException ex) {
    /* log exception message */
}

The StaticMapException instance will be thrown as wrapper of other occurred exception such as IOException or MalformedURLException.

To get map image asynchronously, use another method with Callback param:

Bitmap mapImage;
Callback callback = new Callback() {
    public void onFailed(int code, String msg) {
        /* handle error */
    }
    public void onMapGenerated(Bitmap bitmap) {
        mapImage = bitmap;
    }
};
StaticMap.requestMapImage(context, config, callback);

This method encapsulates AsyncTask class to load image in background.
Note: Callback class methods will be invoked in main thread.


The library support API level 15+. I made this decision considering this post. And I hope this will help to decrease number of preICS devices =)

Have a good coding!


UPDATE (29-12-2014)


Google made its own lite mode of google maps in play services v6.5. So, this library will not be supported anymore.

10 comments:

  1. I always enjoy reading quality articles by an individual who is obviously knowledgeable on their chosen subject. Ill be watching this post with much interest. Keep up the great work, I will be back
    python training in pune | python training institute in chennai | python training in Bangalore

    ReplyDelete
  2. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in velachery| rpa training in tambaram |rpa training in sholinganallur | rpa training in annanagar| rpa training in kalyannagar

    ReplyDelete
  3. I know you feel more happy when you get things done and best of all those things are your most precious treasure.
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    ReplyDelete
  4. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
    Java training in Chennai

    Java Online training in Chennai

    Java Course in Chennai

    Best JAVA Training Institutes in Chennai

    Java training in Bangalore

    Java training in Hyderabad

    Java Training in Coimbatore

    Java Training

    Java Online Training

    ReplyDelete
  5. Thank You For The Auspicious Write-up. It In Reality Used To Be A Amusement Account. VT Markets Glance Advanced To More Introduced Agreeable From You! By The Way, How Can We Communicate?

    ReplyDelete