Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### SDK Manager (download libraries) ###
- Extras -> Google Play services / Google Repository
- ### Libraries (configuring libraries) ###
- 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)
- ### Google Map v2 key ###
- Preferences -> Build -> SHA1 fingerprint (45:83:49:05:GF:96:19:FD:E1:D2:D0:E0:95:04:CC:9F:72:F8:39:54)
- 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
- ### activity_main.xml ###
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" >
- <fragment
- android:id="@+id/map"
- android:name="com.google.android.gms.maps.MapFragment" //SupportMapFragment = below API 7
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
- </RelativeLayout>
- ### MainActivity.java ###
- package jason.jmap;
- import android.os.Bundle;
- import android.support.v7.app.ActionBarActivity;
- import android.view.Menu;
- import android.view.MenuItem;
- import com.google.android.gms.maps.CameraUpdateFactory;
- import com.google.android.gms.maps.GoogleMap;
- import com.google.android.gms.maps.SupportMapFragment;
- import com.google.android.gms.maps.model.LatLng;
- import com.google.android.gms.maps.model.Marker;
- import com.google.android.gms.maps.model.MarkerOptions;
- import com.google.android.gms.maps.model.Polyline;
- import com.google.android.gms.maps.model.PolylineOptions;
- public class MainActivity extends ActionBarActivity {
- static final LatLng MIU = new LatLng(47.914214,106.974389);
- //static final LatLng MIU = new LatLng(47.914214,106.974389);
- //static final LatLng KIEL = new LatLng(53.551, 9.993);
- private GoogleMap map;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- try {
- if (map == null) {
- // above API 11
- map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
- // below API 7
- //map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
- }
- // Instantiates a new Polyline object and adds points to define a rectangle
- PolylineOptions rectOptions = new PolylineOptions()
- .add(new LatLng(47.914214,106.974389))
- .add(new LatLng(47.915537,106.971899))
- .add(new LatLng(47.91663,106.964561))
- .add(new LatLng(47.917593,106.952244))
- .add(new LatLng(47.918154,106.948103));
- // Get back the mutable Polyline
- Polyline polyline = map.addPolyline(rectOptions);
- map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
- //map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
- // Enabling MyLocation Layer of Google Map
- map.setMyLocationEnabled(true);
- Marker miu = map.addMarker(new MarkerOptions().position(MIU).title("MIU"));
- /*Marker kiel = map.addMarker(new MarkerOptions()
- .position(KIEL)
- .title("Kiel")
- .snippet("Kiel is cool")
- .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));*/
- // Move the camera instantly to hamburg with a zoom of 15.
- map.moveCamera(CameraUpdateFactory.newLatLngZoom(MIU, 15));
- // Zoom in, animating the camera.
- map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- ### Mainfest.xml ###
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="jason.jmap"
- android:versionCode="1"
- android:versionName="1.0" >
- <!-- <permission
- android:name="jason.jmap.permission.MAPS_RECEIVE"
- android:protectionLevel="signature" />
- <uses-permission android:name="jason.jmap.permission.MAPS_RECEIVE" /> -->
- <uses-sdk
- android:minSdkVersion="11"
- android:targetSdkVersion="19" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <!-- Required to show current location -->
- <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="jason.jmap.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="AIaSyECHwnS-rRiA-eJFi4KdoyZ2vgv6tY"
- />
- <meta-data
- android:name="com.google.android.gms.version"
- android:value="@integer/google_play_services_version" />
- </application>
- </manifest>
Add Comment
Please, Sign In to add comment