0

私は Android プログラミングの初心者であり、Android 開発者ガイドと YouTube ガイドを実行し、ここで尋ねられた他の同様の質問も確認しましたが、AVD エミュレーターにマップを読み込めません。google-play-services_lib とAndroid ビルド ターゲットもインポート しました: Android 4.2.2 API 17

アプリをエミュレーターに正常にインストールできますが、実行しようとするたびに、「残念ながら、[アプリ] が停止しました」という通知が表示されます。

助けようとする試みは大歓迎です。ここに私のコードがあります:

manifest.xml ファイル:

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

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="17" />
<permission
    android:name="com.android.sitemarker.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
 <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<uses-permission android:name="com.android.sitemarker.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />                                                                                                                                
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.android.sitemarker.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="xxxx-xxxx-xxxxx" />
   </application>

   </manifest>

main.xml ファイル:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity" >
  <fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />




    </RelativeLayout>

MainActivity.java ファイル:

package com.android.sitemarker;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

ログキャット

05-31 08:33:33.989: E/AndroidRuntime(2125):     ... 24 more
4

2 に答える 2

0

Googleマップは実際のデバイスで実行され、エミュレータでは実行されないため、実際のデバイスで実行されない場合は実際のデバイスで試してから、このコードを試してください。また、プロジェクトのプロパティにgoogleplayライブラリを追加していることを適切に確認してください

public class MainActivity extends Activity implements LocationListener{
LocationManager locationManager;
private GoogleMap googleMap;
double latitude=17.385044;
double longitude=78.486671;
private String provider;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 LocationManager service=(LocationManager)getSystemService(LOCATION_SERVICE);
boolean enableGPS= service.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean enableWifi=service.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
 // Check if enabled and if not send user to the GSP settings
    // Better solution would be to display a dialog and suggesting to 
     // go to the settings
 if(!enableGPS){
     Toast.makeText(getApplicationContext(),"Gps signal not found",1).show();
    Intent intent=new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    startActivity(intent);
}
locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
 Criteria criteria = new Criteria();
 provider = locationManager.getBestProvider(criteria, false);
 Location location = locationManager.getLastKnownLocation(provider);

 // Initialize the location fields
 if (location != null) {
     Toast.makeText(this, "Selected Provider " + provider,
             Toast.LENGTH_SHORT).show();
     onLocationChanged(location);
 } else {

     //do something
 }


try {
    //loading map
    initilizeMap();
} catch (Exception e) {
    // TODO: handle exception
e.printStackTrace();
}
}
   private void initilizeMap(){
if(googleMap==null){
googleMap=(MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();    
      //check if map is created succesfully or not
    if(googleMap==null){
  Toast.makeText(getApplicationContext(),"sorry unable to create map",0).show();  
    }
}

MarkerOptions markerOptions=new MarkerOptions().position(new LatLng(緯度、経度)); markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)); CameraPosition cameraPosition=new CameraPosition.Builder().target(new LatLng(17.385044, 78.486671)).zoom(12).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); googleMap.setMyLocationEnabled(真); googleMap.setOnInfoWindowClickListener(null); }

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

/* Remove the locationlistener updates when Activity is paused */
@Override
protected void onPause() {
super.onPause();
locationManager.removeUpdates(this);
}

 public void onLocationChanged(Location location) {
double lat =  location.getLatitude();
double lng = location.getLongitude();
Toast.makeText(this, "Location " + lat+","+lng,
        Toast.LENGTH_LONG).show();
LatLng coordinate = new LatLng(lat, lng);
Toast.makeText(this, "Location " + coordinate.latitude+","+coordinate.longitude,
        Toast.LENGTH_LONG).show();
Marker startPerc = googleMap.addMarker(new MarkerOptions()
.position(coordinate)
.title("Start")
.snippet("Inizio del percorso")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
}


  public void onProviderDisabled(String provider) {
  Toast.makeText(this, "Enabled new provider " + provider,
        Toast.LENGTH_SHORT).show();

   }


  public void onProviderEnabled(String provider) {
  Toast.makeText(this, "Disabled provider " + provider,
        Toast.LENGTH_SHORT).show();

     }


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

  }
于 2013-10-16T13:41:18.260 に答える