Advertisement
pablo7890

GMapsTest

Dec 29th, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package com.gmapstest;
  2.  
  3. import android.os.Bundle;
  4. import android.app.Activity;
  5. import android.view.Menu;
  6. import android.widget.Toast;
  7.  
  8. import com.google.android.gms.maps.GoogleMap;
  9. import com.google.android.gms.maps.MapFragment;
  10.  
  11. public class MainActivity extends Activity {
  12.      
  13.     // Google Map
  14.     private GoogleMap googleMap;
  15.  
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.  
  21.         try {
  22.             // Loading map
  23.             initilizeMap();
  24.  
  25.         } catch (Exception e) {
  26.             e.printStackTrace();
  27.         }
  28.  
  29.     }
  30.  
  31.     /**
  32.      * function to load map. If map is not created it will create it for you
  33.      * */
  34.     private void initilizeMap() {
  35.         if (googleMap == null) {
  36.             googleMap = ((MapFragment) getFragmentManager().findFragmentById(
  37.                     R.id.map)).getMap();
  38.  
  39.             // check if map is created successfully or not
  40.             if (googleMap == null) {
  41.                 Toast.makeText(getApplicationContext(),
  42.                         "Sorry! unable to create maps", Toast.LENGTH_SHORT)
  43.                         .show();
  44.             }
  45.         }
  46.     }
  47.  
  48.     @Override
  49.     protected void onResume() {
  50.         super.onResume();
  51.         initilizeMap();
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement