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);
Location recentLoc = locMgr.getLastKnownLocation(
double lat = recentLoc.getLatitude();
double lon = recentLoc.getLongitude();
String geoURI = String.format("geo:%f,%f?q=
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.
Thanks . Nice work Your intent example useful for me .
ReplyDeleteReport Bugs Topic tells about the bug reports of this blogs.... Thanks for sharing...
ReplyDeleteAndroid Training in Chennai
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
ReplyDeletecan u send the source code of project?
ReplyDelete
ReplyDeleteIam 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..
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