2013-08-09 2 views
4

Я хочу отобразить карту в эмуляторе android. Для этого я установил сервисы Google Play и импортировал их в рабочие области и сделал их ссылками в моем проекте. Но я запускаю приложение, которое показывает игровые сервисы Goolgle, а не на вашем телефоне. Я не могу понять, почему это видно. Я прилагаю полный код здесь ..
Вот мой файл манифеста:Невозможно отобразить карту на Android

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

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="17" /> 

    <permission 
     android:name="com.example.map.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 
    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" /> 
    <uses-permission android:name="com.example.map.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <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.example.map.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="AIzaSyDcNgF68UPm1cNdlJmr41PGYG06z4P_NyI" /> 
    </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" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    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> 

.java file is here 

package com.example.map; 
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 

public class MainActivity extends Activity 
{ 



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

    } 
![enter image description here][1] 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

} 

эмулятор изображения Не могли бы вы дать мне ответ, почему это показывает. Это действительно помогает мне.

+0

Если вы заходите в Project -> Properties -> Android, ваша цель сборки - цель Google API или цель Android? – haventchecked

+0

Проверить эту ссылку он мне помочь: [1]: http://stackoverflow.com/questions/5262695/how-to-get-md5-from-debug-keystore-file/5262845#5262845 [2 ]: http://stackoverflow.com/questions/6305938/how-can-i-get-the-md5-fingerprint-from-javas-keytool-not-only-sha-1 – KOTIOS

+0

в эмуляторе google map не отображается , –

ответ

3

Пункт 1. Использование ниже кода, если вы разрабатываете приложение для уровня API 8.

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

см MapFragment. Используйте этот класс, только если вы настроили таргетинг на API 12 и выше. В противном случае используйте SupportMapFragment.

Пункт 2. Расширьте класс с FragmentActivtiy вместо деятельности

частный GoogleMap Googlemap;

public void loadGoogleMap(){ 
     if(googleMap==null){ 
       // Getting Google Play availability status 
       int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); 
       // Showing status 
       if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available 
        int requestCode = 10; 
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, (Activity)context, requestCode); 
        dialog.show(); 
       }else{ 
       // Getting reference to the SupportMapFragment of activity_main.xml 
        SupportMapFragment fm = (SupportMapFragment) this.YOUR_CLASS_NAME.getSupportFragmentManager() 
         .findFragmentById(R.id.my_comm_nearme_map); 

        // Getting GoogleMap object from the fragment 
        googleMap = fm.getMap(); 

        //setting map type 
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 

        UiSettings uiSettings = googleMap.getUiSettings(); 
        uiSettings.setCompassEnabled(false); 
        uiSettings.setZoomControlsEnabled(true); 
        uiSettings.setMyLocationButtonEnabled(false); 
       } 
     } 
    } 

Пункт 3.

But i run application it shows Goolgle play services in not in Your phone. 

Android нужно Google Play services для запуска карты. Вы можете загрузить его с рынка и повторите попытку, Карты будут работать.

Если у вас возникла ошибка при установке Google Play services, ваше устройство несовместимо.

1

enter image description here Пожалуйста, перейдите на Google API, так и на API v2 Google Maps для Android Только

Google API Console -> Сервис -> Google Maps Android API v2 ->

чем generte нового ключа API и тестирования.

0

используйте этот код для запуска настроенной карты Google ниже уровня api-11, она также успешно работает на более высоких версиях.

импортировать проект google-play-services_lib в рабочее пространство из \ sdk \ extras \ google \ google_play_services_froyo \ libproject.

правой кнопкой мыши, чтобы перейти к проекту-> properties-> android-> щелкните правой кнопкой мыши флажок в имени панели библиотеки как «есть библиотека» и нажмите «Применить» и нажмите «ОК».

теперь переходим к вашим проектам недвижимости-android-> в библиотеке Panel-> нажмите адд> теперь выбрать «Google-плей-services_lib» в опцию-> Применить> ОК

Теперь используйте этот код

package com.hmkcode.android; 

    import android.os.Bundle; 
    import android.support.v4.app.FragmentActivity; 

    import com.google.android.gms.maps.CameraUpdateFactory; 
    import com.google.android.gms.maps.GoogleMap; 
    import com.google.android.gms.maps.SupportMapFragment; 
    import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
    import com.google.android.gms.maps.model.LatLng; 
    import com.google.android.gms.maps.model.MarkerOptions; 

public class MainActivity extends FragmentActivity { 

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

     try { 
      GoogleMap map; 
      map = ((SupportMapFragment) getSupportFragmentManager() 
        .findFragmentById(R.id.map)).getMap(); 
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
        19.233442, 72.980851), 16)); 
      map.addMarker(new MarkerOptions() 
        .icon(BitmapDescriptorFactory 
          .fromResource(R.drawable.house_flag)) 
        .anchor(0.0f, 1.0f) 
        .position(new LatLng(19.233442, 72.980851)) 
        .title("Hello world")); 

     } catch (NullPointerException e) { 

     } 

    } 

} 

расположение.XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <fragment 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 

манифеста

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

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

    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true"/> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <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.hmkcode.android.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="use your obtained key" /> 

     <meta-data android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
    </application> 

</manifest> 

теперь вы можете увидеть карту еще вы увидите кнопку, которая может быть использована для обновления услуг.

Смежные вопросы