<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps"></activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps"></activity>
</application>
public class MainActivity extends AppCompatActivity {
private Button ubicarme;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ubicarme=(Button)findViewById(R.id.ubicarme);
ubicarme.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent =new Intent(MainActivity.this,MapsActivity.class);
startActivity(intent);
}
});
}
}
public class MainActivity extends AppCompatActivity {
private Button ubicarme;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ubicarme=(Button)findViewById(R.id.ubicarme);
ubicarme.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent =new Intent(MainActivity.this,MapsActivity.class);
startActivity(intent);
}
});
}
}
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
int status= GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (status== ConnectionResult.SUCCESS){
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}else {
Dialog dialog=GooglePlayServicesUtil.getErrorDialog(status,(Activity) getApplicationContext(),10);
dialog.show();
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
UiSettings uiSettings=mMap.getUiSettings();
uiSettings.setZoomControlsEnabled(true);
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Hola").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET)));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
float zoomlevel=16;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,zoomlevel));
}
}
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
int status= GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (status== ConnectionResult.SUCCESS){
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}else {
Dialog dialog=GooglePlayServicesUtil.getErrorDialog(status,(Activity) getApplicationContext(),10);
dialog.show();
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
UiSettings uiSettings=mMap.getUiSettings();
uiSettings.setZoomControlsEnabled(true);
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Hola").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET)));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
float zoomlevel=16;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,zoomlevel));
}
}
Error que muestra