Mobile Programming Dr. Mohsin Ali Memon.

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 4 Overview Overview of Sensors Programming Tutorial 1: Tracking location with GPS and Google.
Advertisements

GPS and MapView. First In the emulator, set the time zone to something (e.g., east coast) and check that the time is correct. Otherwise, the gps emulator.
CS378 - Mobile Computing Maps. Using Google Maps Like other web services requires an API key from Google ons/google-apis/mapkey.html.
Chapter 11: Discover! Incorporating Google Maps
Lecture 13 Mobile Programming Google Maps Android API.
Location-Based Services: Part 2 (Google Maps)
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
Android Development (Basics)
CS378 - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives: Open Street Maps –
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Programming with Android: The Google Maps Library Slides taken from Luca Bedogni Marco Di Felice.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Google Maps Android API v2 吳俊興 國立高雄大學 資訊工程學系 CSF645 – Mobile Computing 行動計算
PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse 
Social Media Apps Programming Min-Yuh Day, Ph.D. Assistant Professor Department of Information Management Tamkang University
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
Android - Broadcast Receivers
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
Maps Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
Android Application Lifecycle and Menus
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Cosc 5/4735 YouTube API. YouTube The YouTube Android Player API enables you to incorporate video playback functionality into your Android applications.
Google map v2.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
CS371m - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives Exist: – Open Street Maps –
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Location-Based Services. Objectives How to display Google Maps in your application How to control displayed maps How to perform geocoding and reverse.
Lab7 – Appendix.
Introduction to android
Android Programming - Features
Android Application Maps 1.
Location-Based Services: Part 2 (Google Maps)
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Android Widgets 1 7 August 2018
Sensors, maps and fragments:
The GoogleMap API By Cody Littley.
תכנות ב android אליהו חלסצ'י.
CIS 470 Mobile App Development
CS371m - Mobile Computing Maps.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Programming with Android: The Google Maps Library
CMPE419 Mobile Application Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Mobile Programming Gestures in Android.
Adding Components to Activity
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Activities and Fragments
CS 240 – Advanced Programming Concepts
Mobile Programmming Dr. Mohsin Ali Memon.
Activities, Fragments, and Intents
CIS 470 Mobile App Development
External Services CSE 5236: Mobile Application Development
Mobile Programming Broadcast Receivers.
Android Sensor Programming
External Services CSE 5236: Mobile Application Development
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Mobile Programming Dr. Mohsin Ali Memon

Google Maps API V2 The Google Maps Android API allows you to display a Google map in your Android application.  In version 1 of Google Maps for Android, Google used the MapView to display map data. In version 2, the MapView is deprecated; instead, you have to use a MapFragment. In addition, you no longer need to create a project that targets the Google APIs platform, as Google has migrated a lot of services into Google Play services. http://mobiforge.com/design-development/developing-with-google-maps-v2-android

Step 1 The first step in using Google Maps v2 for Android is to download the Google Play Services SDK. The Google Play Services SDK contains the APIs needed by Google Maps and hence you need to download this and reference it in your Android application. The next step is to import the Google Play Service Library project into your workspace so that you can import it into your Android project. Adding this Library to your current project

Step 2 Enabling Google Maps for your Application Using the Web browser on your computer, go to the Google APIs Console located athttps://code.google.com/apis/console. Go to

Step 3: Getting the Maps API Key In order to use Google Maps v2 for Android, you need to apply for a Maps API key. In order to apply for a Maps API key, you need to pass Google the SHA1 hash of the certificate that you will use for signing your app. C:\Program Files\Java\jdk1.7.0_21\bin> keytool -list -alias androiddebugkey -keystore "<path of debug.keystore>" -storepass android -keypass android –v

Generating Keys

Configuring Android key for Google Maps API

Configuring AndroidManifest file Back in Eclipse, enter the following code in AndroidManifest.xml. Be sure to take note of the package name of your project as well as put it the Maps API key that you have obtained in the previous step <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="<Your_MAPS_API_KEY>" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Adding Permissions to the Manifest <uses-permission android:name="com.example.testgooglemaps.permission.MAPS_RECEIVE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name= "com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name= "android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

The Layout file Replace the current code with <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" />

MainActivity import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { GoogleMap map; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); map = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map)).getMap(); if (map == null) { Toast.makeText(this, "Google Maps not available", Toast.LENGTH_LONG).show(); } } }

Adding menu options @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; }

Main.xml <item android:id="@+id/menu_showcurrentlocation" android:orderInCategory="100" android:showAsAction="never" android:title="Show Current Location"/> android:id="@+id/menu_lineconnecttwopoints" android:title="Line connecting 2 points"/> </menu> <menu xmlns:android="http://schemas.android.co m/apk/res/android" > <<item android:id="@+id/menu_zoomin" android:orderInCategory="100" android:showAsAction="never" android:title="Zoom In"/> <item android:id="@+id/menu_zoomout" android:title="Zoom Out"/> <item android:id="@+id/menu_gotolocation" android:orderInCategory="100" android:showAsAction="never" android:title="Go to a location"/> android:id="@+id/menu_addmarker" android:title="Add a marker"/> android:id="@+id/menu_getcurrentlocation" android:title="Get Current Location"/>

Main Activity cont’d case R.id.menu_gotolocation: CameraPosition cameraPosition = new CameraPosition.Builder() .target(MEHRAN_UET) // Sets the center of the map to // Mehran UET Jamshoro .zoom(17) // Sets the zoom .bearing(90) // Sets the orientation of the camera to east .tilt(30) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition( cameraPosition)); break; case R.id.menu_getcurrentlocation: // ---get your current location and display a blue dot--- map.setMyLocationEnabled(true); private static final LatLng MEHRAN_UET = new LatLng(25.4081,68.2603); private static final LatLng NIAZ_STADIUM = new LatLng(25.3824,68.3382); . @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_zoomin: map.animateCamera(CameraUpdateFactory.zoomIn()); break; case R.id.menu_zoomout: map.animateCamera(CameraUpdateFactory.zoomOut());

Main Activity cont’d case R.id.menu_lineconnecttwopoints: case R.id.menu_showcurrentlocation: Location myLocation = map.getMyLocation(); LatLng myLatLng = new LatLng(myLocation.getLatitude(), myLocation.getLongitude()); CameraPosition myPosition = new CameraPosition.Builder() .target(myLatLng).zoom(17).bearing(90).tilt(30).build(); map.animateCamera( CameraUpdateFactory.newCameraPosition(myPosition)); break; case R.id.menu_lineconnecttwopoints: //---add a marker at Niaz Stadium--- map.addMarker(new MarkerOptions() .position(NIAZ_STADIUM) .title(“niaz") .snippet(“stadium") .icon(BitmapDescriptorFactory.defaultMarker( BitmapDescriptorFactory.HUE_AZURE))); //---draw a line connecting MUET and Niaz Dtadium map.addPolyline(new PolylineOptions() .add(MEHRAN_UET, NIAZ_STADIUM).width(5).color(Color.RED)); break; } return true;}