3

Androidプログラミングは初めてです.Androidデバイス(4.1.2)に簡単なGoogleマップを表示しようとしています。

ActivityManifest.xml にすべてのアクセス許可と Google API キーを追加しました

これは activity_maps.xml です

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment 
     android:id="@+id/map"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     class="com.google.android.gms.maps.MapFragment"/>

</RelativeLayout>

これは MapsActivity.java です

package com.example.androidmapsapp;

import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.maps.MapActivity;

public class MapsActivity extends MapActivity {

GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    try {
        // Loading map
        initilizeMap();

    } catch (Exception e) {
        e.printStackTrace();
    }

    //GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    //googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.maps, menu);
    return true;
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().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();
        }
    }
}

@Override
protected void onResume() {
    super.onResume();
    initilizeMap();
}

}

丸太の猫

09-26 17:09:51.476: E/Trace(26750): error opening trace file: No such file or directory (2)
09-26 17:09:51.501: I/System.out(26750): Sending WAIT chunk
09-26 17:09:51.501: W/ActivityThread(26750): Application com.example.androidmapsapp is waiting for the debugger on port 8100...
09-26 17:09:51.526: I/dalvikvm(26750): Debugger is active
09-26 17:09:51.716: I/System.out(26750): Debugger has connected
09-26 17:09:51.716: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:51.916: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.116: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.316: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.516: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.716: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.921: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:53.121: I/System.out(26750): debugger has settled (1377)
09-26 17:09:54.416: D/dalvikvm(26750): threadid=1: still suspended after undo (sc=1 dc=1)
09-26 17:11:15.291: E/Trace(27618): error opening trace file: No such file or directory (2)
09-26 17:11:15.306: I/System.out(27618): Sending WAIT chunk
09-26 17:11:15.306: W/ActivityThread(27618): Application com.example.androidmapsapp is waiting for the debugger on port 8100...
09-26 17:11:15.316: I/dalvikvm(27618): Debugger is active
09-26 17:11:15.506: I/System.out(27618): Debugger has connected
09-26 17:11:15.506: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:15.706: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:15.906: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.106: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.306: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.511: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.711: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.911: I/System.out(27618): debugger has settled (1404)
09-26 17:11:18.246: D/dalvikvm(27618): threadid=1: still suspended after undo (sc=1 dc=1)
09-26 17:11:23.271: D/dalvikvm(27618): threadid=1: still suspended after undo (sc=1 dc=1)
09-26 17:11:23.271: D/dalvikvm(27618): GC_CONCURRENT freed 172K, 9% free 9639K/10503K, paused 22ms+4ms, total 56ms
09-26 17:11:23.276: W/CursorWrapperInner(27618): Cursor finalized without prior close()

「setContentView(R.layout.activity_maps);」のデバッグ中 ソースが見つかりません!

4

1 に答える 1

1

あなたの問題は、MapActivityGoogle Map API V1 では正しいが、Google Maps API V2 では使用しないでください。使用する必要があるのは、ターゲットにしているプラ​​ットフォームに応じて単純Activityまたはです。FragmentActivity

あなたの場合、この行を変更してみてください:

public class MapsActivity extends MapActivity {

これに:

public class MapsActivity extends Activity {

それでも問題が解決しない場合は、Google Maps API V2 をアプリケーションに統合するために私が書いたこのブログ投稿にアクセスして、これが役立つかどうかを確認してください。

Google マップ API V2

于 2013-09-27T06:32:52.970 に答える