Проблемы с Android Google Maps API v2 (

1

Я пытаюсь создать приложение Google Maps API v2 в Eclipse, и я продолжаю использовать ряд ошибок, которые я не уверен, как их решить.

Начинал кодирование приложений Android на несколько дней назад (и кодирование вообще около 2 недель назад), поэтому все это для меня все еще очень ново.

Я получил SHA и MD5, мой ключ API v2, зарегистрировал его в Google и т.д.

Я не знаю, где я ошибаюсь!

Здесь CatLog при попытке запустить приложение для Android:

>11-18 16:02:19.756: E/Trace(16453): error opening trace file: No such file or directory (2)
>11-18 16:02:19.756: D/ActivityThread(16453): setTargetHeapUtilization:0.25

>11-18 16:02:19.756: D/ActivityThread(16453): setTargetHeapIdealFree:8388608

>11-18 16:02:19.756: D/ActivityThread(16453): setTargetHeapConcurrentStart:2097152

>11-18 16:02:19.816: W/dalvikvm(16453): threadid=1: thread exiting with uncaught exception (group=0x412b5438)

>11-18 16:02:19.826: E/AndroidRuntime(16453): FATAL EXCEPTION: main

>11-18 16:02:19.826: E/AndroidRuntime(16453): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.deliveryfor/com.deliveryfor.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2081)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2106)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at 
android.app.ActivityThread.access$600(ActivityThread.java:138)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204
)
>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.os.Handler.dispatchMessage(Handler.java:99)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.os.Looper.loop(Looper.java:137)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.app.ActivityThread.main(ActivityThread.java:4921)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at java.lang.reflect.Method.invokeNative(Native Method)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at java.lang.reflect.Method.invoke(Method.java:511)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at dalvik.system.NativeStart.main(Native Method)

>11-18 16:02:19.826: E/AndroidRuntime(16453): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.view.LayoutInflater.inflate(LayoutInflater.java:489)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.view.LayoutInflater.inflate(LayoutInflater.java:396)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.view.LayoutInflater.inflate(LayoutInflater.java:352)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:398)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.app.Activity.setContentView(Activity.java:2087)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.deliveryfor.MainActivity.onCreate(MainActivity.java:24)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.app.Activity.performCreate(Activity.java:5234)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   ... 11 more

>11-18 16:02:19.826: E/AndroidRuntime(16453): Caused by: java.lang.IllegalStateException: The meta-data tag in your app AndroidManifest.xml does not have the right value.  Expected 4030500 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.maps.internal.q.v(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.maps.internal.q.u(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.dynamic.a.a(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.dynamic.a.onInflate(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.app.Activity.onCreateView(Activity.java:4889)

>11-18 16:02:19.826: E/AndroidRuntime(16453):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-18 16:02:19.826: E/AndroidRuntime(16453):    ... 21 more

Честно говоря, я не уверен, как вывести любые решения из этого гигантского блока красного цвета. Вот элементы моего проекта:

Основная деятельность:

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends Activity {
    private final LatLng LOCATION_STATE = new LatLng(49.27645, -122.917587);
    private final LatLng LOCATION_CITY = new LatLng(49.187500, -122.849000);
    private final LatLng LOCATION_YOU = new LatLng(49.187500, -122.849000);

    private GoogleMap map;

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

        map  = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

        map.addMarker(new MarkerOptions().position(LOCATION_YOU).title("This is you!"));
    }

    @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;
    }

    public void onClick_State(View v) {
//      CameraUpdate update = CameraUpdateFactory.newLatLng(LOCATION_BURNABY);
        map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_YOU, 9);
        map.animateCamera(update);
    }
    public void onClick_City(View v) {
        map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_CITY, 14);
        map.animateCamera(update);

    }
    public void onClick_You(View v) {
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_STATE, 20);
        map.animateCamera(update);

    }

}

activity_main.java

<?xml version="1.0" encoding="utf-8"?>
<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" >

    <TextView
        android:id="@+id/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

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

    <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="You" 
        android:onClick="onClick_You" 
        android:layout_alignParentTop="true" 
        android:layout_alignParentRight="true" 
        android:id="@+id/btnYou"/> 

    <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="City" 
        android:onClick="onClick_City" 
        android:layout_alignParentTop="true" 
        android:id="@+id/btnCity" 
        android:layout_centerHorizontal="true"/> 

    <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="State" 
        android:onClick="onClick_State" 
        android:layout_alignParentTop="true"  
        android:id="@+id/btnState" 
        android:layout_alignParentLeft="true"/>



</RelativeLayout>

AndroidManifest:

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

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />  

    <uses-permission android:name="com.deliveryfor.permission.MAPS_RECEIVE"/> 
    <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" 
        android:debuggable="true">

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyBK2qJjm02TrBMNd9eza7PuyRGxWNpxng0"/>

        <activity
            android:name="com.deliveryfor.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>
    </application>

</manifest>
Теги:
google-maps
google-maps-api-2

2 ответа

0
Лучший ответ

Чтобы протестировать ваше приложение, вам необходимо настроить SDK Google Play Services, пожалуйста, обратитесь к этой ссылке и добавьте этот тег в файл манифеста:

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

Ваш логарифм указывает на это:

>11-18 16:02:19.826: E/AndroidRuntime(16453): Caused by: java.lang.IllegalStateException: The meta-data tag in your app AndroidManifest.xml does not have the right value.  
Expected 4030500 but found 0.  
You must have the following declaration within the <application> element:     
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
  • 0
    это сработало. однако теперь у меня есть ошибка аутентификации, которая, я уверен, означает, что мне просто нужно заново выполнить процесс API. «11-18 16: 57: 39.691: E / Google Maps Android API (19832): ошибка авторизации. Инструкции по правильной настройке карты см. На сайте developers.google.com/maps/documentation/android/start . 11-18 16: 57: 39.701: E / Google Maps Android API (19832): убедитесь, что приведенное ниже соответствует тому, что находится в консоли API: Имя пакета: com.deliveryfor, ключ API: AIzaSyBK2qJjm02TrBMNd9eza7PuyRGxWNpxng0, отпечаток пальца сертификата: 86F0AA2DDF637DFDFDF6464DFDF640640564675564440564464640564464464640575564464
0

Из вашего журнала:

java.lang.IllegalStateException: The meta-data tag in your app AndroidManifest.xml does not have the right value.  Expected 4030500 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Переместите тэг метаданных непосредственно перед закрывающим тегом.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню