aquaballoon

Android - Google Map V2

Mar 23rd, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.77 KB | None | 0 0
  1. ### SDK Manager (download libraries) ###
  2. Extras -> Google Play services / Google Repository
  3.  
  4. ### Libraries (configuring libraries) ###
  5. Properties -> Android -> Google APIs -> Library -> appcompat_v7 / google-play-services_lib(import from ./android-sdk/extras/google/google_play_services/libproject/google-play-service_lib)
  6.  
  7. ### Google Map v2 key ###
  8. Preferences -> Build -> SHA1 fingerprint (45:83:49:05:GF:96:19:FD:E1:D2:D0:E0:95:04:CC:9F:72:F8:39:54)
  9. https://cloud.google.com/console -> 45:83:49:05:GF:96:19:FD:E1:D2:D0:E0:95:04:CC:9F:72:F8:39:54:jason.jmap -> AIaSyECHwnS-rRiA-eJFi4KdoyZ2vgv6tY
  10.  
  11.  
  12. ### activity_main.xml ###
  13.  
  14. <?xml version="1.0" encoding="utf-8"?>
  15. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  16.     android:layout_width="fill_parent"
  17.     android:layout_height="fill_parent" >
  18.  
  19.     <fragment
  20.         android:id="@+id/map"
  21.         android:name="com.google.android.gms.maps.MapFragment"  //SupportMapFragment = below API 7
  22.         android:layout_width="match_parent"
  23.         android:layout_height="match_parent"/>
  24.  
  25. </RelativeLayout>
  26.  
  27. ### MainActivity.java ###
  28.  
  29. package jason.jmap;
  30.  
  31. import android.os.Bundle;
  32. import android.support.v7.app.ActionBarActivity;
  33. import android.view.Menu;
  34. import android.view.MenuItem;
  35.  
  36. import com.google.android.gms.maps.CameraUpdateFactory;
  37. import com.google.android.gms.maps.GoogleMap;
  38. import com.google.android.gms.maps.SupportMapFragment;
  39. import com.google.android.gms.maps.model.LatLng;
  40. import com.google.android.gms.maps.model.Marker;
  41. import com.google.android.gms.maps.model.MarkerOptions;
  42. import com.google.android.gms.maps.model.Polyline;
  43. import com.google.android.gms.maps.model.PolylineOptions;
  44.  
  45.  
  46. public class MainActivity extends ActionBarActivity {
  47.  
  48.     static final LatLng MIU = new LatLng(47.914214,106.974389);
  49.     //static final LatLng MIU = new LatLng(47.914214,106.974389);
  50.     //static final LatLng KIEL = new LatLng(53.551, 9.993);
  51.     private GoogleMap map;
  52.  
  53.     @Override
  54.     protected void onCreate(Bundle savedInstanceState) {
  55.         super.onCreate(savedInstanceState);
  56.         setContentView(R.layout.activity_main);
  57.  
  58.         try {
  59.  
  60.             if (map == null) {
  61.                 // above API 11
  62.                 map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
  63.                 // below API 7
  64.                 //map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
  65.             }
  66.  
  67.             // Instantiates a new Polyline object and adds points to define a rectangle
  68.             PolylineOptions rectOptions = new PolylineOptions()
  69.                     .add(new LatLng(47.914214,106.974389))
  70.                     .add(new LatLng(47.915537,106.971899))
  71.                     .add(new LatLng(47.91663,106.964561))
  72.                     .add(new LatLng(47.917593,106.952244))
  73.                     .add(new LatLng(47.918154,106.948103));
  74.  
  75.             // Get back the mutable Polyline
  76.             Polyline polyline = map.addPolyline(rectOptions);
  77.  
  78.             map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
  79.             //map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
  80.  
  81.             // Enabling MyLocation Layer of Google Map
  82.             map.setMyLocationEnabled(true);
  83.  
  84.             Marker miu = map.addMarker(new MarkerOptions().position(MIU).title("MIU"));
  85.                         /*Marker kiel = map.addMarker(new MarkerOptions()
  86.                         .position(KIEL)
  87.                         .title("Kiel")
  88.                         .snippet("Kiel is cool")
  89.                         .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));*/
  90.  
  91.             // Move the camera instantly to hamburg with a zoom of 15.
  92.             map.moveCamera(CameraUpdateFactory.newLatLngZoom(MIU, 15));
  93.  
  94.             // Zoom in, animating the camera.
  95.             map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
  96.  
  97.         } catch (Exception e) {
  98.             e.printStackTrace();
  99.         }
  100.     }
  101.  
  102.  
  103.     @Override
  104.     public boolean onCreateOptionsMenu(Menu menu) {
  105.        
  106.         // Inflate the menu; this adds items to the action bar if it is present.
  107.         getMenuInflater().inflate(R.menu.main, menu);
  108.         return true;
  109.     }
  110.  
  111.     @Override
  112.     public boolean onOptionsItemSelected(MenuItem item) {
  113.         // Handle action bar item clicks here. The action bar will
  114.         // automatically handle clicks on the Home/Up button, so long
  115.         // as you specify a parent activity in AndroidManifest.xml.
  116.         int id = item.getItemId();
  117.         if (id == R.id.action_settings) {
  118.             return true;
  119.         }
  120.         return super.onOptionsItemSelected(item);
  121.     }
  122.  
  123. }
  124.  
  125. ### Mainfest.xml ###
  126.  
  127. <?xml version="1.0" encoding="utf-8"?>
  128. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  129.     package="jason.jmap"
  130.     android:versionCode="1"
  131.     android:versionName="1.0" >
  132.  
  133. <!--     <permission
  134.         android:name="jason.jmap.permission.MAPS_RECEIVE"
  135.         android:protectionLevel="signature" />
  136.  
  137.     <uses-permission android:name="jason.jmap.permission.MAPS_RECEIVE" /> -->
  138.  
  139.     <uses-sdk
  140.         android:minSdkVersion="11"
  141.         android:targetSdkVersion="19" />
  142.  
  143.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  144.     <uses-permission android:name="android.permission.INTERNET" />
  145.     <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
  146.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  147.  
  148.    <!--  Required to show current location -->
  149.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  150.     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  151.  
  152.    <!--  Required OpenGL ES 2.0. for Maps V2 -->
  153.     <uses-feature
  154.         android:glEsVersion="0x00020000"
  155.         android:required="true" />
  156.  
  157.     <application
  158.         android:allowBackup="true"
  159.         android:icon="@drawable/ic_launcher"
  160.         android:label="@string/app_name">
  161.         <activity
  162.             android:name="jason.jmap.MainActivity"
  163.             android:label="@string/app_name"
  164.             android:theme="@style/AppBaseTheme">
  165.             <intent-filter>
  166.                 <action android:name="android.intent.action.MAIN" />
  167.  
  168.                 <category android:name="android.intent.category.LAUNCHER" />
  169.             </intent-filter>
  170.         </activity>
  171.  
  172.       <!--   Goolge API Key -->
  173.        <meta-data
  174.             android:name="com.google.android.maps.v2.API_KEY"
  175.             android:value="AIaSyECHwnS-rRiA-eJFi4KdoyZ2vgv6tY"
  176.             />
  177.         <meta-data
  178.             android:name="com.google.android.gms.version"
  179.             android:value="@integer/google_play_services_version" />
  180.        
  181.     </application>
  182.  
  183. </manifest>
Add Comment
Please, Sign In to add comment