Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gmapstest;
- import android.os.Bundle;
- import android.app.Activity;
- import android.view.Menu;
- import android.widget.Toast;
- import com.google.android.gms.maps.GoogleMap;
- import com.google.android.gms.maps.MapFragment;
- public class MainActivity extends Activity {
- // Google Map
- private GoogleMap googleMap;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- try {
- // Loading map
- initilizeMap();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * function to load map. If map is not created it will create it for you
- * */
- private void initilizeMap() {
- if (googleMap == null) {
- googleMap = ((MapFragment) getFragmentManager().findFragmentById(
- R.id.map)).getMap();
- // check if map is created successfully or not
- if (googleMap == null) {
- Toast.makeText(getApplicationContext(),
- "Sorry! unable to create maps", Toast.LENGTH_SHORT)
- .show();
- }
- }
- }
- @Override
- protected void onResume() {
- super.onResume();
- initilizeMap();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement