Android: Using Google maps app to show places in your application

When we are developing android application with maps functionality normally developers tries to use Google maps API for this. But if your requirement is simple it may be more easy and effective to use existing maps application by a intent. In this application I'm going to show how to show the nearest hospital in your application.

Note- To make this work your app and emulator must be created using Google APIs not android APIs. (Both are the same but if you are not using Google maps API map application functionality is not available to you).

Here is the code,

LocationManager  locMgr  = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location recentLoc = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double lat = recentLoc.getLatitude();
double lon = recentLoc.getLongitude();
String geoURI = String.format("geo:%f,%f?q=hospital", lat, lon);
Uri geo = Uri.parse(geoURI);
Intent geoMap = new Intent(Intent.ACTION_VIEW, geo);
startActivity(geoMap);


In the geoURI string you can change the hospital in to any other place. If you just wan't to center the map to your location do not include the question mark and latter part in geoURI .

This is how my application shows the nearest hospital to my location.

If you test this in Android emulator you have to send your location to the emulator using DDMS in eclipse because. Otherwise it will throw a null pointer exception. You can find articles on how to do this in internet. 

Comments

  1. Thanks . Nice work Your intent example useful for me .

    ReplyDelete
  2. Report Bugs Topic tells about the bug reports of this blogs.... Thanks for sharing...

    Android Training in Chennai

    ReplyDelete
  3. Am using Android studio with enable apis and after integrate this code and run then showing error:please enable api in developer console link but am already enabled

    ReplyDelete
  4. can u send the source code of project?

    ReplyDelete

  5. Iam so thrilled because of finding your alluring website here.Actually i was searching for Android.Your blog is so astounding and informative too..Iam very happy to find such a creative blog. Iam also find another one by mistake while am searching the same topicIOS Development.Thank you soo much..

    ReplyDelete
  6. A good detox shampoo removes all dirt, drug metabolites, and toxins from your hair and scalp without harming your hair or scalp's health. Here are some additional general guidelines for selecting the best drug detox for you: Natural ingredients that are gentle on your scalp and hair, such as green tea extract and apple cider vinegar, should be included in the product. Look for botanical extracts like lemon, mint, and sage in the product. These items keep your hair and scalp healthy while also ensuring that it smells good. Some detox shampoos are harsh on your hair, making it look and feel even worse. If your hair is already in bad shape, a complex shampoo could exacerbate the problem. Visit: https://www.urineworld.com/

    ReplyDelete

Post a Comment

Popular posts from this blog

Create new Java Class files at runtime

Using iReport plugin for Jasper Reports in Netbeans

Fixing Error "Failed to load VMMR0.r0 (VERR_SUPLIB_WORLD_WRITABLE)" in Virtualbox