I have got the API key but still I am unable to open the google map in my project. my requirement is I have to get the current location and nearby hospital details in my app using google map and I want the list of hospitals near to that place in increasing order as per the distance. after clicking on my one of the hospital we can able to show the navigable path from current place to that particular hospital. Please find the UI part belowenter image description here Please help me.
Asked
Active
Viewed 51 times
-2
-
Show us what you have tried you code and Stack trace if any. – Jay Rathod Apr 22 '16 at 12:28
1 Answers
0
Firstly let me ask you, What you had done till now ? Because based on your coding, Any developer can suggest you. Any How , Please Follow this..
Define XML such like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Initialize you google map in MainActivity
public class MainActivity extends Activity {
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
And Most Important Define your Manifest File properly with all permissions
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="packagename"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="packagename.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="packagename.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="packagename.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBZMlkOv4sj-M5JO9p6wksdax4TEjDVLgo" />
</application>

kitkat
- 142
- 10