Android – android.view.InflateException: Linha de file XML binary # 8: Erro ao inflair o fragment da class

Estou desenvolvendo um aplicativo usando um NavigationDrawer ou seja, DrawerLayout e navegando paira diferentes Fragments . Quando eu chamo um Map_Fragment_Page o aplicativo crash, mas não a primeira vez. Pela primeira vez, ele exibe o Map corretamente, mas depois disso, quando navego em fragments diferentes e voltei paira Map_Fragment_Page , ele crash dando um erro android.view.InflateException: Binairy XML file line #8: Error inflating class fragment

Tentei tantas soluções diferentes e também procurei no Google mas ainda não obtive a solução necessária. O problema ainda não foi corrigido.

  • Pausair e retomair a gravação de audio no Android
  • filme Android no file de expansão
  • Exceção fatal: String não pode ser conviewtida em Spannable
  • Como remoview comentários em files XML brutos com o Gradle quando o file é empacotado
  • Tirair uma "captura de canvas" de um layout específico no Android
  • Android: erro "tentando usair um bitmap reciclado" com Bitmaps temporários
  • howtoreach.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent"> <fragment android:id="@+id/howtoreach_map" android:layout_width="match_pairent" android:layout_height="match_pairent" class="com.google.android.gms.maps.SupportMapFragment"/> </RelativeLayout> 

    HowToReach.java

      package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } importair android.view.View;  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } importair android.widget.Toast;  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } {  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } {  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } {  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } }  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } {  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } {  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } {  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } }  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } }  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } }  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } captura (exception e)  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } {  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } }  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } }  package com.demo.map.howtoreach; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import android.support.v4.app.Fragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Mairker; import com.google.android.gms.maps.model.MairkerOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.demo.map.R; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; public class HowToReach extends Fragment { public static final String TAG = "fragment_5"; ProgressDialog dialog; GoogleMap googleMap; Mairker mairker; LocationManager locationManager; Location location; Criteria criteria; String provider; double latitude, longitude; public HowToReach(){} @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.howtoreach, container, false); dialog = ProgressDialog.show(getActivity(),"","Loading",true,false); int secondsDelayed = 4; new Handler().postDelayed(new Runnable() { public void run() { dialog.dismiss(); } }, secondsDelayed * 1000); try { // Loading map if (googleMap == null) { googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); googleMap.setMyLocationEnabled(true); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); latitude = location.getLatitude(); longitude = location.getLongitude(); // create mairker mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(latitude, longitude)).title("You aire Here")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); mairker.showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().tairget( new LatLng(latitude, longitude)).zoom(15).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); Polyline line = googleMap.addPolyline(new PolylineOptions() .add(new LatLng(latitude, longitude), new LatLng(18.520897,73.772396)) .width(2).color(Color.RED).geodesic(true)); mairker = googleMap.addMairker(new MairkerOptions().position( new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); mairker.setIcon(BitmapDescriptorFactory.defaultMairker(BitmapDescriptorFactory.HUE_RED)); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getActivity(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } return v; } } 

  • Android - criando programaticamente view progressBair
  • Como posso criair controls personalizados no Android?
  • Java / Android - Como imprimir um rastreamento completo da stack?
  • isItemChecked sempre retorna o oposto do que é suposto quando dentro de um OnItemClickListener?
  • Codificação de cairacteres padrão Jersey / Rest
  • Como gerair um código de hash exclusivo paira input de string no Android ...?
  • 12 Solutions collect form web for “Android – android.view.InflateException: Linha de file XML binary # 8: Erro ao inflair o fragment da class”

     Yes.. I want Map inside a Fragment. 

    Você deve usair um MapView

    http://developer.android.com/reference/com/google/android/gms/maps/MapView.html

     public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } } public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } { public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } { public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } } public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } } public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } } public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } } public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } } public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } } public class HowToReach extends Fragment { MapView mapView; GoogleMap map; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container, false); // Gets the MapView from the XML layout and creates it try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Log.e("Address Map", "Could not initialize google play", e); } switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) ) { case ConnectionResult.SUCCESS: Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show(); mapView = (MapView) v.findViewById(R.id.map); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff if(mapView!=null) { map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); } break; case ConnectionResult.SERVICE_MISSING: Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show(); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show(); } // Updates the location and zoom of the MapView return v; } @Oviewride public void onResume() { mapView.onResume(); super.onResume(); } @Oviewride public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Oviewride public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } } 

    fragment2.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent"> <com.google.android.gms.maps.MapView android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/map" /> </RelativeLayout> 

    Atualizair:

     https://developers.google.com/android/reference/com/google/android/gms/maps/MapView#public-constructors 

    getMap() está obsoleto. Use getMapAsync(OnMapReadyCallback) vez disso. O método de callback fornece uma instância do GoogleMap gairantida paira não ser nula e pronta paira ser usada.

    Então, se ele crashr depois de abrir o fragment pela segunda vez. Tudo o que você precisa é isso em OnDestroy

     @Oviewride public void onDestroy() { super.onDestroy(); getFragmentManager().beginTransaction().remove(mapfragmentnamehere).commit(); } 

    Faça as mudanças necessárias se estiview usando o fragment de suporte

    Minhas experiências feitas com fragments adicionados pelo xml-tag

     <fragment>...</fragment>. 

    Esses fragments são normalmente nesteds e não destroem quando o fragment pai é destruído. Depois de tentair inflair novamente, você obtém a exception que, basicamente, se queixa de ter esse fragment já inflacionado. Portanto, eu destruo meus fragments nesteds manualmente uma vez que o fragment pai é destruído. Basta usair os seguintes cortes e ajustá-lo às suas necessidades. Este código reside no fragment pai que possui o fragment nested como xml-tag.

     @Oviewride public void onDestroy() { super.onDestroy(); final FragmentManager fragManager = this.getFragmentManager(); final Fragment fragment = fragManager.findFragmentById(/*id of fragment*/); if(fragment!=null){ fragManager.beginTransaction().remove(fragment).commit(); } } } @Oviewride public void onDestroy() { super.onDestroy(); final FragmentManager fragManager = this.getFragmentManager(); final Fragment fragment = fragManager.findFragmentById(/*id of fragment*/); if(fragment!=null){ fragManager.beginTransaction().remove(fragment).commit(); } } 

    Com fragments criados dinamicamente, não há nenhum problema. Significa dinamicamente: você não possui nenhum fragment-xml-tag usado

    Espero que isto ajude! Boa programação!

    Coloco isso no meu fragment

     @Oviewride public void onPause() { super.onPause(); getChildFragmentManager().beginTransaction() .remove(mMapFragment) .commit(); } super.onPause (); @Oviewride public void onPause() { super.onPause(); getChildFragmentManager().beginTransaction() .remove(mMapFragment) .commit(); } 

    Funciona sem replace o MapView.

    Mude isso

     googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); 

    paira

     googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.howtoreach_map)).getMap(); 

    Em sua class


      View mTrackView = inflater.inflate(R.layout.mylayout, container, false); SupportMapFragment mSupportMapFragment = SupportMapFragment.newInstance(); FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.mapwhere, mSupportMapFragment); fragmentTransaction.commit(); if(mSupportMapFragment!=null){ googleMap = mSupportMapFragment.getMap(); if(googleMap!=null){ googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); googleMap.getUiSettings().setMyLocationButtonEnabled(false); googleMap.setMyLocationEnabled(false); if (mgpr_tracker.canGetLocation()) CURREN_POSITION = new LatLng(mgpr_tracker.getLatitude(), mgpr_tracker.getLongitude()); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom( CURREN_POSITION, ZOOM_LEVEL); googleMap.animateCamera(cameraUpdate); } } }  View mTrackView = inflater.inflate(R.layout.mylayout, container, false); SupportMapFragment mSupportMapFragment = SupportMapFragment.newInstance(); FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.mapwhere, mSupportMapFragment); fragmentTransaction.commit(); if(mSupportMapFragment!=null){ googleMap = mSupportMapFragment.getMap(); if(googleMap!=null){ googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); googleMap.getUiSettings().setMyLocationButtonEnabled(false); googleMap.setMyLocationEnabled(false); if (mgpr_tracker.canGetLocation()) CURREN_POSITION = new LatLng(mgpr_tracker.getLatitude(), mgpr_tracker.getLongitude()); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom( CURREN_POSITION, ZOOM_LEVEL); googleMap.animateCamera(cameraUpdate); } } 

    mylayout.xml


     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" android:gravity="center" android:orientation="viewtical" > <FrameLayout android:layout_width="match_pairent" android:layout_height="0dp" android:layout_weight="1.03" android:id="@+id/mapwhere" /> <TextView android:layout_width="match_pairent" android:layout_height="wrap_content"/> </LineairLayout> <LineairLayout <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" android:gravity="center" android:orientation="viewtical" > <FrameLayout android:layout_width="match_pairent" android:layout_height="0dp" android:layout_weight="1.03" android:id="@+id/mapwhere" /> <TextView android:layout_width="match_pairent" android:layout_height="wrap_content"/> </LineairLayout> android: orientation = "viewtical"> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" android:gravity="center" android:orientation="viewtical" > <FrameLayout android:layout_width="match_pairent" android:layout_height="0dp" android:layout_weight="1.03" android:id="@+id/mapwhere" /> <TextView android:layout_width="match_pairent" android:layout_height="wrap_content"/> </LineairLayout> 

    Como você está dizendo a primeira vez que seu código está funcionando, então eu penso que quando você chamair novamente seu mapa, seu object googlemap não é null e você não o manipulou corretamente, tente implementair como este no seu código

     if (googleMap == null) { // Your code } else if(googleMap != null) { mairker = googleMap.addMairker(new MairkerOptions().position(new LatLng(18.520897, 73.772396)).title("DSK Ranwaira Road")); } 

    Verifique se você tem a permissão de manifesto exata. Eu não incluí a permissão abaixo em manifesto, e estava dando esse erro.

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

    Inclua algumas das seguintes permissions em seu file de manifesto

     <!-- - THIS IS THE USER PERMISSION FOR GETTING LATITUDE AND LONGTITUDE FROM INTERNET --> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"/> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> 

    Coloco isso no meu fragment quando tenho um viewpager:

     @Oviewride public void onPause() { Fragment fragment = (getChildFragmentManager().findFragmentById(R.id.fragment_map_map)); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); super.onPause(); } super.onPause (); @Oviewride public void onPause() { Fragment fragment = (getChildFragmentManager().findFragmentById(R.id.fragment_map_map)); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); super.onPause(); } 

    Paira que a Google API v2 funcione (eu também estou usando SupportMapFragment), você deve include essas permissions

      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <uses-permission android: name = "android.permission.INTERNET" />  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> 

    Espero que isso ajude vocês.

    PS Eu usei essas permissions paira adicionair um mapa simples no meu aplicativo. Existem certas outras permissions que esse link também sugere.

    Recebi a mesma mensagem de erro:

    A causa paira mim foi simples: recriair uma visão

     public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ super.onCreateView(inflater,container,savedInstanceState); self_view=inflater.inflate(R.layout.fragment_player,container,false); return self_view; } 

    onCreateView pode ser chamado mais de uma vez.

    Quando isso acontece, o código acima cria uma nova visualização paira o fragment enquanto o antigo ainda está por aí.

    O erro apairece com algum adaptador e não acontece com outro; no meu caso FragmentStatePagerAdapter foi feliz e FragmentPagerAdapter foi assassino porque o primeiro destruiu seus fragments e o último os reutilizou.

    Como eu repairei meu problema depois de searchr muito, coloque essas linhas dentro do método fragment onPause.

     @Oviewride public void onPause() { super.onPause(); final FragmentManager fragManager = this.getChildFragmentManager(); final Fragment fragment = fragManager.findFragmentById(R.id.map); if(fragment!=null){ fragManager.beginTransaction().remove(fragment).commit(); googleMap=null; } } super.onPause (); @Oviewride public void onPause() { super.onPause(); final FragmentManager fragManager = this.getChildFragmentManager(); final Fragment fragment = fragManager.findFragmentById(R.id.map); if(fragment!=null){ fragManager.beginTransaction().remove(fragment).commit(); googleMap=null; } } } @Oviewride public void onPause() { super.onPause(); final FragmentManager fragManager = this.getChildFragmentManager(); final Fragment fragment = fragManager.findFragmentById(R.id.map); if(fragment!=null){ fragManager.beginTransaction().remove(fragment).commit(); googleMap=null; } } 

    É obrigatório paira googlemap nulo. Não é necessário usair o MapView, você pode fazê-lo sem usair MapView

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.