Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用google maps时膨胀类片段时出错_Android_Google Maps_Android Fragments_Google Maps Android Api 2 - Fatal编程技术网

Android 使用google maps时膨胀类片段时出错

Android 使用google maps时膨胀类片段时出错,android,google-maps,android-fragments,google-maps-android-api-2,Android,Google Maps,Android Fragments,Google Maps Android Api 2,我正在尝试在我的android应用程序中实现谷歌地图。我遵循了指南,但我得到了“错误膨胀类片段”,我不知道是什么错了 我的布局文件: <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent"

我正在尝试在我的android应用程序中实现谷歌地图。我遵循了指南,但我得到了“错误膨胀类片段”,我不知道是什么错了

我的布局文件:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>
清单(将我的真实api密钥替换为“我的api密钥”):


试试这个

SupportMapFragment map =(SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
map.getMapAsync(this);
让MainActivity在MapReadyCallback上实现。 当map就绪时,我们通过回调获得map对象

@Override
public void onMapReady(GoogleMap googleMap) {
    this.googleMap = googleMap; 
}`

我已经在我的应用程序中实现了谷歌地图api v2

试试这个代码

xml文件

<fragment
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        class="com.google.android.gms.maps.MapFragment"/>

如果这对您有帮助,请不要忘记将此答案作为正确答案…

谢谢您的回复,我刚刚发现我做错了什么。我在手机中启用了usb数据传输,这就是应用程序崩溃的原因。真不敢相信我犯了这样一个新手错误。

你在使用Eclipse还是Android Studio?您的项目中是否集成了Google Play服务?我正在使用eclipse,并将Google Play服务添加到了我的项目中。
@Override
public void onMapReady(GoogleMap googleMap) {
    this.googleMap = googleMap; 
}`
<fragment
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        class="com.google.android.gms.maps.MapFragment"/>
//extends activity and implements onMapReady
public class map_activity extends Activity implements OnMapReadyCallback {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myfile_layout);
}

 @Override
public void onMapReady(GoogleMap googleMap) {
    //do everything with the map
    //change the map type
    googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

    // Creating a LatLng object for the current locati
    LatLng latLng = new LatLng(23.634501, -102.552784);

    // Showing the current location in Google Map
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
}
}