2011-12-14 11 views
0

私はGPSアプリケーションを作りたいと思います。このコードは別のチュートリアルのコピー貼りです。しかし、私はアプリをテストすると、それは空白とマップが表示されません!誰でも助けてくれるの???ここでAndroid GPSマップ

は、ここでは、コード

package com.manita.mapuse; 

import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.view.KeyEvent; 
import android.widget.Toast; 

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 



public class MapuseActivity extends MapActivity implements LocationListener { 
    private MapView mapView = null; 
    private LocationManager lm = null; 
    private double lat = 0; 
    private double lng = 0; 
    private MapController mc = null; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    mapView = (MapView) this.findViewById(R.id.mapView); 
    mapView.setBuiltInZoomControls(true); 

    lm = (LocationManager) this.getSystemService(LOCATION_SERVICE); 
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this); 
    lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this); 

    mc = mapView.getController(); 
    mc.setZoom(12); 
    } 

    @Override 
    protected boolean isRouteDisplayed() 
    { 
    return false; 
    } 

    @Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    { 
    if (keyCode == KeyEvent.KEYCODE_S) 
    { 
    mapView.setSatellite(!mapView.isSatellite()); 
    return true; 
    } 
    return super.onKeyDown(keyCode, event); 
    } 

    @Override 
    public void onLocationChanged(Location location) 
    { 
    lat = location.getLatitude(); 
    lng = location.getLongitude(); 
    Toast.makeText(getBaseContext(), 
    "Location change to : Latitude = " + lat + " Longitude = " + lng, 
    Toast.LENGTH_SHORT).show(); 
    GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); 
    mc.animateTo(p); 
    mc.setCenter(p); 
    } 

    @Override 
    public void onProviderDisabled(String provider) 
    { 
    // TODO Auto-generated method stub 

    } 

    @Override 
    public void onProviderEnabled(String provider) 
    { 
    // TODO Auto-generated method stub 

    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) 
    { 
    // TODO Auto-generated method stub 

    } 
} 

あるありがとうのmanifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.manita.mapuse" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="7" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <uses-library android:name="com.google.android.maps" /> 
     <activity 
      android:label="@string/app_name" 
      android:name=".MapuseActivity" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

    </application> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_GPS" /> 
<uses-permission android:name="android.permission.LOCATION" /> 
</manifest> 

であり、これは

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/mainlayout" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <com.google.android.maps.MapView 
android:id="@+id/mapView" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:enabled="true" 
android:clickable="true" 
android:apiKey="@string/mapKey" 
/> 
    <LinearLayout android:id="@+id/zoom" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     /> 

</RelativeLayout> 

私MainActivity.xmlです。

+2

Google MAP APIキーを確認してください。 – Arslan

+0

私はここから得たマップAPIキーを持っています[http://code.google.com/intl/fr/android/maps-api-signup.html] !! –

+0

デバッグキーから生成されたキーですか?エミュレータ上のマップではデータが表示されず、タイルが表示されない場合... – Prasham

答えて

0

エミュレータでコードをテストしていると仮定します。これを見てみましょう:http://blogspot.fluidnewmedia.com/2009/04/displaying-google-maps-in-the-android-emulator/

+0

私はAVD yesでテストしています!私はmapkeyを1回しか持っていませんでしたが、コードを何度も変更しました。何が間違っているの?複数のマップキーを取得できますか?またはちょうど1つ??はいの場合、どうすれば別のmd5を入手できますか? –

+0

あなたはリンクの指示に従いましたか? keytool.exe -list -alias androiddebugkey -keystore "C:\ path_to_android \ debug.keystore" -storepass android -keypass android –

+0

yessさんはしました!私は1つ以上のmd5指紋を得ることができると思った!しかしそれはちょうど1つです! @Noureddine AMRI –

0

アプリが白い場合は、Googleマップ用の新しいAPIキーを作成することが考えられます。私はまったく同じ問題を抱えていた。あなたが作成した後、それをマニフェストの中に入れて、あなたはいいです。