Java MapView在片段中显示空白地图(Android map API V2)
我目前正在开发一个与谷歌地图集成的应用程序。然而,它并没有像我期望的那样运行。它什么也没显示,只是一个空白的灰色屏幕 我已经检查了我的adb和Java MapView在片段中显示空白地图(Android map API V2),java,android,google-maps,google-maps-api-2,Java,Android,Google Maps,Google Maps Api 2,我目前正在开发一个与谷歌地图集成的应用程序。然而,它并没有像我期望的那样运行。它什么也没显示,只是一个空白的灰色屏幕 我已经检查了我的adb和grep Auth授权中似乎没有任何错误。这意味着它可以消除错误的可能性API\u键。 我想知道我没有看到的可能性是什么。我希望能在这里找到一些见解 我的清单 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission androi
grep Auth
授权中似乎没有任何错误。这意味着它可以消除错误的可能性API\u键。
我想知道我没有看到的可能性是什么。我希望能在这里找到一些见解
我的清单
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="[Removed]"/>
public class CurrentLocationFragment extends Fragment implements OnMapReadyCallback {
private MapView mapView;
private GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_current_location, null);
FragmentManager fm = getChildFragmentManager();
mapView = (MapView) view.findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
//initialize the map
try {
MapsInitializer.initialize(this.getActivity());
} catch (Throwable e) {
e.printStackTrace();
}
//animate the camera
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
map.animateCamera(cameraUpdate);
return view;
}
我的片段XML
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
任何洞察都会非常宝贵!谢谢。您使用的是Android Studio吗?默认情况下,你可以创建一个地图应用程序,这太简单了,以后你可以更改MainActivity,然后像第二个或第三个Activity一样放置
按照以下步骤创建你的应用程序按以下方式使用地图^^访问我检查过的问题,答案是一样的。Logcat最终向我显示,我在“console.google.com”中的SH1指纹与我的debug.keystore不匹配。
public class CurrentLocationFragment extends Fragment implements OnMapReadyCallback {
private MapView mapView;
private GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_current_location, null);
FragmentManager fm = getChildFragmentManager();
mapView = (MapView) view.findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
//initialize the map
try {
MapsInitializer.initialize(this.getActivity());
} catch (Throwable e) {
e.printStackTrace();
}
//animate the camera
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
map.animateCamera(cameraUpdate);
return view;
}