16th February 2012

Integrating with Google Maps

Guides | Tutorial By 5 years ago

Sometimes it makes perfect sense for an app to have map based functionality, and on Android the usual way to proceed is to use the Google Maps api library and embed a MapView directly into your app. This is fine If the mapping functionality the app requires is relatively simple, but what if you require more complex functionality like directions and route plotting? While these requirements are possible with the library there is quite a bit plumbing that needs to be undertaken.

So what else can you do? Well what better way to handle mapping functionality than to offload the work to an app designed specifically for the task a.k.a Google Maps. With a few lines of code you can have Google Maps load with a marker on a specific location, with the added benefits of giving users all the functionality that Google Maps contains.

So how do we do it?

String uri = "http://maps.google.com/maps?q=%s";
Intent mapIntent = new Intent(
    Uri.parse(String.format(Uri, address));

Want to load google maps with a path between a start address and a destination? The following code gets this done quickly and easily.

String uri = "http://maps.google.com/maps?saddr=%s&daddr=%s"
Intent intent = new Intent(
    Uri.parse(String.format(uri, startAddr, destinationAddr));

You can even omit the starting address to use the current location as the starting point

String uri = "http://maps.google.com/maps?daddr=%s"
Intent intent = new Intent(
    Uri.parse(String.format(uri, destinationAddr));

Like everything there are a couple of drawbacks with this method that need to be weight up. If there are multiple apps on the users device that can handle the intent they will be displayed in a list possible options. This means that Google Maps may not be the application the user ultimately chooses and assumptions may be broken. The second issue is that the user will be taken away from your app and pushed to an app developed by somebody else. While this may not be a major issue, as they will be brought back to the original app when they hit the back button, it’s something to keep in mind.

Recommended Posts

Write JNI wrappers for Android

Post by 5 years ago

Following are the steps that you need to follow┬áin order to make things working – 1. Setting up the NDK on my machine 2. Learn how to write JNI wrappers 3. Learn C++ briefly so

Got an idea?

We help entrepreneurs, organizations and established brands from around
the country bring ideas to life. We would love to hear from you!