In this tutorial we’ll make an Android Google Map example program. Along with that I’ll also show how to create a splash screen and how to sign your APKs so you can distribute your app.
If you combine what I cover here with my Android ActionBar tutorial you’ll be able to add more functionality to your Google Map quite easily. All of the code used can be found after the video below.
If you like videos like this, please share on Google Plus with a click here [googleplusone]
Code from the Videos
activity_splash_screen.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imgLogo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/google_maps_logo" /> </RelativeLayout> |
SplashScreen.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package com.newthinktank.derekbanas.mappy; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; public class SplashScreen extends Activity{ private static int SPLASH_SCREEN_DELAY = 3000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash_screen); new Handler().postDelayed(new Runnable() { @Override public void run() { // Executed after timer is finished (Opens MainActivity) Intent intent = new Intent(SplashScreen.this, MainActivity.class); startActivity(intent); // Kills this Activity finish(); } }, SPLASH_SCREEN_DELAY); } } |
AndroidManifest.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.newthinktank.derekbanas.mappy" > <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <permission android:name="com.newthinktank.derekbanas.mappy.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <activity android:name=".SplashScreen" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" android:label="@string/app_name" > </activity> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="APIKEY"/> </application> </manifest> |
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 |
<?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" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout> |
MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
package com.newthinktank.derekbanas.mappy; import android.app.Activity; import android.os.Bundle; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends Activity { // Constant for defining latitude and longitude static final LatLng DerekPos = new LatLng(40 , -79); // GoogleMap class private GoogleMap googleMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // verify we can interact with the Google Map try { if (googleMap == null) { googleMap = ((MapFragment) getFragmentManager(). findFragmentById(R.id.map)).getMap(); } // Show a satellite map with roads /* MAP_TYPE_NORMAL: Basic map with roads. MAP_TYPE_SATELLITE: Satellite view with roads. MAP_TYPE_TERRAIN: Terrain view without roads. */ googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); // Place dot on current location googleMap.setMyLocationEnabled(true); // Turns traffic layer on googleMap.setTrafficEnabled(true); // Enables indoor maps googleMap.setIndoorEnabled(true); // Turns on 3D buildings googleMap.setBuildingsEnabled(true); // Show Zoom buttons googleMap.getUiSettings().setZoomControlsEnabled(true); // Create a marker in the map at a given position with a title Marker marker = googleMap.addMarker(new MarkerOptions(). position(DerekPos).title("Hello")); } catch (Exception e) { e.printStackTrace(); } } } |
Hi Derek a huge thank you god bless you . Can you please show us how to use Nearby places Search Requests & Text Search Requests , results on a listview with Name Address Distance from Location and image.pull to refresh (On Item Click will show on map ,On Item long Click 2 option 1.Share intent 2.Add to Favorite) and all this for And all this for phone and tablet as fragments A&B when for tablet fragment A is a
sided Listvew.
Hope not asking too much, but I really need your help .
Thanks a million and continue with the great work you do god bless …
You’re very welcome 🙂 I plan on making some large Android apps like you mentioned. May God bless you as well.