【发布时间】:2018-08-31 11:54:32
【问题描述】:
您好,我的谷歌地图有问题,它只能在模拟器上运行,而不能在真实设备上运行。
这是我的 google_map_api.xml:
<resources>
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIza...</string
还有我的清单:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIza..." />
和我的班级:
public class MapsActivity extends Fragment implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_maps, container, false);
final SupportMapFragment map = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
map.getMapAsync(this);
return rootView;
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
try {
boolean success = googleMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
this.getActivity(), R.raw.mapstyle));
} catch (Resources.NotFoundException e) {
}
return true;
}
});
}
}
【问题讨论】:
-
您在哪些设备上测试过此代码?你连接到互联网了吗?
-
可能重复:stackoverflow.com/questions/50807764/… 在那篇帖子中查看我的答案
标签: android google-maps