Posts

Showing posts from March, 2012

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

Image
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 geoUR…