@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.menu_solicitar_servico:
new EnviaServicoTask(this).execute();
break;
case R.id.menu_lista_servico:
Intent vaiParaServicos = new Intent(this,ServicoActivity.class);
startActivity(vaiParaServicos);
break;
case R.id.menu_mapa_usuario:
Intent vaiParaMapa = new Intent(this,PeruberMapsActivity.class);
startActivity(vaiParaMapa);
break;
}
return super.onOptionsItemSelected(item);
}
XML
<item android:id="@+id/menu_mapa_usuario"
android:title="Mapa"
android:icon="@drawable/ic_mapa"
app:showAsAction="always"/>
Chave API
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyCHQNU6AxiYo7LW9nDmAB4WXJmDzSL21dE</string>
Manifest
<activity android:name=".ServicoActivity" />
<activity android:name=".DetalhesServicoActivity" />
<activity android:name=".ServicoTabletActivity" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".PeruberMapsActivity"
android:label="@string/title_activity_peruber_maps"></activity>
Minha Classe
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class PeruberMapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_peruber_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
Os nomes é diferente do que é ministrado no curso, mas a estrutura é exatamente a mesma coisa..