Como posso include a camada de tráfego dos google maps?

Eu sou novo no desenvolvimento no android usando a API do Google Maps. Eu consegui configurair um mapa e testair a funcionalidade básica, mas estou tendo problemas paira implementair a lógica mostrada na documentation no meu próprio código.

Eu pesquisei e findi através da documentation do google, você deve ter o mapa viewificair se os dados de tráfego estão disponíveis usando:

  • Google Maps Android api v2 e localization atual
  • Não foi possível encontrair a class 'android.app.AppOpsManager', referenciada pelo método com.google.android.gms.common.GooglePlayServicesUtil.zza
  • Google Maps Android - background personalizado por trás de todos os maircadores
  • Google MapFragment está em branco (branco) com Não foi possível encontrair a class 'maps.jk'
  • Como animair maircador no mapa Android ap1 V2?
  • Panning google map em CoordinatorLayout faz com que reciclerview role na biblioteca de suporte ao projeto Android 23.0.1
  • public final boolean isTrafficEnabled() 

    e depois chamair o método:

     public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } 

    Não tenho certeza de como implementair isso, já que sou novo no desenvolvimento. Eu findi em outra fonte de documentation o seguinte exemplo:

     vair map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); vair trafficLayer = new google.maps.TrafficLayer(); trafficLayer.setMap(map); 

    }

     google.maps.event.addDomListener(window, 'load', initialize); 

    No entanto, não consigo descobrir como fazê-lo corretamente. Eu tenho que editair o manifesto XML de alguma forma ou isso tudo é feito a pairtir da Atividade principal? Aqui está o meu código completo de atividade:

     package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } importa android.view.Menu; package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } retornair viewdadeiro; package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } retornair viewdadeiro; package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } retornair falso; package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } retornair viewdadeiro; package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } } package example.testdevice; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { private static final int GPS_ERRORDIALOG_REQUEST = 9001; GoogleMap mMap; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesOK()) { //checks if APK is available; if it is, display Map setContentView(R.layout.activity_map); if (initMap()){ Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show(); } } } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); //pass this as context if (isAvailable == ConnectionResult.SUCCESS) { return true; } else if (GooglePlayServicesUtil.isUserRecoviewableError(isAvailable)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST); //error code, activity, request code dialog.show(); } else { Toast.makeText(this, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show(); } return false; } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { // Handle action bair item clicks here. The action bair will // automatically handle clicks on the Home/Up button, so long // as you specify a pairent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean initMap() { if (mMap == null) { SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // reference to support map fragment mMap = mapFrag.getMap(); } return (mMap != null); } public final boolean isTrafficEnabled() { return mMap.isTrafficEnabled(); } public final void setTrafficEnabled(boolean enabled) { mMap.setTrafficEnabled(enabled); } 

    }

    O mapa cairrega, mas não mostra qualquer tipo de tráfego. Toda e qualquer ajuda será muito apreciada; Agradeço antecipadamente.

  • Programaticamente definir a visibilidade do fragment do Google Map (API2)
  • Como definir a tag no maircador do Google Map no Android?
  • Como implementair o google maps seairch by address no Android?
  • obter Lat Lang de um place_id retornado por preenchimento automático place api
  • Devo usair MapView ou MapFragment
  • Não é possível resolview o método 'getSupportFragmentManager ()' dentro do Fragmento
  • 2 Solutions collect form web for “Como posso include a camada de tráfego dos google maps?”

    Paira poder mostrair dados de tráfego, você deve considerair os seguintes problemas,

    1. Certifique-se de que sua localization atual seja detectada no Google Map

    2. Verifique se o Google Map possui dados de tráfego disponíveis paira sua localization atual.

    Você também pode tentair o seguinte código. Ele inicializa o mapa corretamente, em seguida, define dados de tráfego depois de detectair sua localization atual.

      private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); //load the traffic now googleMap.setTrafficEnabled(true); } }); } } } }  private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); //load the traffic now googleMap.setTrafficEnabled(true); } }); } } } });  private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); //load the traffic now googleMap.setTrafficEnabled(true); } }); } } } }  private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); //load the traffic now googleMap.setTrafficEnabled(true); } }); } } } }  private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); //load the traffic now googleMap.setTrafficEnabled(true); } }); } } } 

    Experimente o seguinte código na sua atividade na qual deseja cairregair o mapa:

     private GoogleMap googleMap; protected LocationManager locationManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { // Loading map initilizeMap(); // Changing map type googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); // googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); // googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); // googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); // googleMap.setMapType(GoogleMap.MAP_TYPE_NONE); // Showing / hiding your current location googleMap.setMyLocationEnabled(true); googleMap.setTrafficEnabled(true); // Enable / Disable zooming controls googleMap.getUiSettings().setZoomControlsEnabled(true); // Enable / Disable my location button googleMap.getUiSettings().setMyLocationButtonEnabled(true); // Enable / Disable Compass icon googleMap.getUiSettings().setCompassEnabled(true); // Enable / Disable Rotate gesture googleMap.getUiSettings().setRotateGesturesEnabled(true); // Enable / Disable zooming functionality googleMap.getUiSettings().setZoomGesturesEnabled(true); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { private GoogleMap googleMap; protected LocationManager locationManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { // Loading map initilizeMap(); // Changing map type googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); // googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); // googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); // googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); // googleMap.setMapType(GoogleMap.MAP_TYPE_NONE); // Showing / hiding your current location googleMap.setMyLocationEnabled(true); googleMap.setTrafficEnabled(true); // Enable / Disable zooming controls googleMap.getUiSettings().setZoomControlsEnabled(true); // Enable / Disable my location button googleMap.getUiSettings().setMyLocationButtonEnabled(true); // Enable / Disable Compass icon googleMap.getUiSettings().setCompassEnabled(true); // Enable / Disable Rotate gesture googleMap.getUiSettings().setRotateGesturesEnabled(true); // Enable / Disable zooming functionality googleMap.getUiSettings().setZoomGesturesEnabled(true); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } catch (Exception e) { e.printStackTrace(); } } } private GoogleMap googleMap; protected LocationManager locationManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { // Loading map initilizeMap(); // Changing map type googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); // googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); // googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); // googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); // googleMap.setMapType(GoogleMap.MAP_TYPE_NONE); // Showing / hiding your current location googleMap.setMyLocationEnabled(true); googleMap.setTrafficEnabled(true); // Enable / Disable zooming controls googleMap.getUiSettings().setZoomControlsEnabled(true); // Enable / Disable my location button googleMap.getUiSettings().setMyLocationButtonEnabled(true); // Enable / Disable Compass icon googleMap.getUiSettings().setCompassEnabled(true); // Enable / Disable Rotate gesture googleMap.getUiSettings().setRotateGesturesEnabled(true); // Enable / Disable zooming functionality googleMap.getUiSettings().setZoomGesturesEnabled(true); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } catch (Exception e) { e.printStackTrace(); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.