Advertisement
cephurs

goog api

Oct 24th, 2013
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.googlemaps;
  2. import com.google.android.maps.MapActivity;
  3. import android.os.Bundle;
  4. import android.view.Menu;
  5.  
  6. public class MainActivity extends MapActivity{
  7.  
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.activity_main);
  12. }
  13.  
  14. @Override
  15. protected boolean isRouteDisplayed() {
  16. // TODO Auto-generated method stub
  17. return true;
  18. }
  19.  
  20. }
  21.  
  22. <?xml version="1.0" encoding="utf-8"?>
  23. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  24. package="com.example.googlemaps"
  25. android:versionCode="1"
  26. android:versionName="1.0" >
  27.  
  28. <uses-sdk android:minSdkVersion="8"/>
  29. <uses-permission android:name="android.permission.INTERNET" />
  30.  
  31. <application
  32. android:allowBackup="true"
  33. android:icon="@drawable/ic_launcher"
  34. android:label="@string/app_name"
  35. android:theme="@style/AppTheme" >
  36. <uses-library android:name="com.google.android.maps" />
  37. <activity
  38. android:name="com.androidhive.googlemaps.MainActivity"
  39. android:label="@string/app_name" >
  40. <intent-filter>
  41. <action android:name="android.intent.action.MAIN" />
  42. <category android:name="android.intent.category.LAUNCHER" />
  43. </intent-filter>
  44. </activity>
  45. </application>
  46.  
  47. </manifest>
  48.  
  49. <?xml version="1.0" encoding="utf-8"?>
  50. <com.google.android.maps.MapView
  51. xmlns:android="http://schemas.android.com/apk/res/android"
  52. android:id="@+id/mapView"
  53. android:layout_width="fill_parent"
  54. android:layout_height="fill_parent"
  55. android:clickable="true"
  56. android:apiKey="@string/Api_key"
  57. />
  58.  
  59. <fragment
  60. android:id="@+id/map"
  61. android:layout_width="fill_parent"
  62. android:layout_height="fill_parent"
  63. class="com.google.android.gms.maps.SupportMapFragment" />
  64.  
  65. <meta-data
  66. android:name="com.google.android.maps.v2.API_KEY"
  67. android:value="YOUR-API-KEY" />
  68.  
  69. int status = GooglePlayServicesUtil
  70. .isGooglePlayServicesAvailable(getBaseContext());
  71.  
  72. if (status != ConnectionResult.SUCCESS) {
  73. // Google Play Services are not available
  74.  
  75. int requestCode = 10;
  76. Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,
  77. requestCode);
  78. dialog.show();
  79.  
  80. } else {
  81. // Google Play Services are available
  82.  
  83. // Getting reference to the SupportMapFragment
  84. SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager()
  85. .findFragmentById(R.id.map);
  86.  
  87. // Getting Google Map
  88. myMap = fragment.getMap();
  89.  
  90. // Enabling MyLocation in Google Map
  91. myMap.setMyLocationEnabled(true);
  92.  
  93. // Getting LocationManager object from System Service
  94. // LOCATION_SERVICE
  95. LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
  96.  
  97. // Creating a criteria object to retrieve provider
  98. Criteria criteria = new Criteria();
  99.  
  100. // Getting the name of the best provider
  101. String provider = locationManager.getBestProvider(criteria, true);
  102.  
  103. // Getting Current Location From GPS
  104. Location location = locationManager.getLastKnownLocation(provider);
  105.  
  106. if (location != null) {
  107. onLocationChanged(location);
  108. }
  109.  
  110. locationManager.requestLocationUpdates(provider, 20000, 0, this);
  111. }
  112.  
  113. int resultCode = GooglePlayServicesUtil
  114. .isGooglePlayServicesAvailable(getApplicationContext());
  115.  
  116. if (resultCode == ConnectionResult.SUCCESS) {
  117.  
  118. } else {
  119. GooglePlayServicesUtil.getErrorDialog(resultCode, this,
  120. RQS_GooglePlayServices);
  121. }
  122.  
  123. mGoogleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
  124. .getMap(); } }
  125.  
  126. <uses-sdk
  127. android:minSdkVersion="8"
  128. android:targetSdkVersion="17" />
  129.  
  130. <permission
  131. android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
  132. android:protectionLevel="signature" />
  133.  
  134. <uses-feature
  135. android:glEsVersion="0x00020000"
  136. android:required="true" />
  137.  
  138. <uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
  139.  
  140. <application
  141. android:allowBackup="true"
  142. android:icon="@drawable/ic_launcher"
  143. android:label="@string/app_name"
  144. android:theme="@style/AppTheme" >
  145. <activity
  146. android:name="com.vogella.android.locationapi.maps.MainActivity"
  147. android:label="@string/app_name" >
  148. <intent-filter>
  149. <action android:name="android.intent.action.MAIN" />
  150.  
  151. <category android:name="android.intent.category.LAUNCHER" />
  152. </intent-filter>
  153. </activity>
  154.  
  155. <meta-data
  156. android:name="com.google.android.maps.v2.API_KEY"
  157. android:value="AIzaSyDeYchyvOUsy_I68_RMtfsI5QVkqweIp9w" />
  158. </application>
  159.  
  160. <fragment
  161. android:id="@+id/map"
  162. android:layout_width="match_parent"
  163. android:layout_height="match_parent"
  164. class="com.google.android.gms.maps.SupportMapFragment" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement