我正在努力在屏幕上显示一个简单的 map 。我遇到的问题是 map 未加载。它只是显示一个空白屏幕,角落里有谷歌的标志。这是 map 工作的代码。
try {
// Loading map
initializeMap();
marker = new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(title)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.locate_icon));
marker.anchor(0.5f, 0.5f);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(marker);
moveToCurrentLocation(new LatLng(latitude, longitude));
} catch (Exception e) {
e.printStackTrace();
}
private void moveToCurrentLocation(LatLng currentLocation) {
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation,
15));
// Zoom in, animating the camera.
googleMap.animateCamera(CameraUpdateFactory.zoomIn());
// Zoom out to zoom level 10, animating with a duration of 2 seconds.
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
}
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
任何 在这方面的帮助将不胜感激。
最佳答案
如果您可以在左下角看到 google Logo 但无法查看 map 本身,那么问题很明显,您的 AndroidManifest 中没有正确的 map API key 。
要解决这个问题,请登录或创建一个新的 Google Developer's Console 帐户并生成一个新的映射键并将其放入项目的 AndroidManifest 文件中。 Please refer to this link for more information.
关于Android:Google map 未显示在屏幕上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33933600/