我刚刚创建了一个新项目,并添加了API密钥, 当我尝试运行该项目时,Google地图将无法加载
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mapproblem.zakaria.maptestprobleme.MapsActivity" />
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_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));
}
}
E / Google Maps Android API:授权失败。请参阅https://developers.google.com/maps/documentation/android-api/start,了解如何正确设置地图。 E / Google Maps Android API:在Google Developer Console(https://console.developers.google.com)中 确保已启用“ Google Maps Android API v2”。 确保存在以下Android密钥: API密钥:AIzaSgYrFTjKL2hp0SLKaTd_-1rVdwxOQy1VDu0 Android应用程序(;):55:FA:14:99:28:28:D7:43:0F:19:62:E4:10:7C:7A:67:8F:AA:10:6C; com.map问题zakaria.maptestprobleme
答案 0 :(得分:0)
您应转到google developer console并为您的项目启用google map api,然后在顶部工具栏上选择您的项目,然后在仪表板部分选择Enabled APIs and services
,搜索Google Map Api然后启用它
答案 1 :(得分:0)
仅添加密钥是不够的。您需要按照错误提示启用Maps Android API。
打开Google Cloud platform,选择您的项目,然后转到“ API和服务”>“库”。搜索Android版Maps SDK并启用它。
这应该可以纠正错误。