8

मैं Google मानचित्र API v2 का उपयोग करके एक एप्लिकेशन बनाने की कोशिश कर रहा हूं लेकिन बात यह है कि एप्लिकेशन मुझे बल बंद कर देता है हालांकि मैंने सभी आवश्यक निर्देशों का पालन किया।Google मानचित्र API v2 काम नहीं कर रहा है

यहाँ एंड्रॉयड हिस्सा

import android.support.v4.app.FragmentActivity; 
import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 

public class GPSonMap extends FragmentActivity{ 

MapView map; 
MapController controller; 
LocationManager locationManager; 
LocationListener listener; 
PendingIntent pendingIntent ; 
Criteria criteria; 
MapOverlay overlay; 


@Override 
public void onCreate(Bundle onsaved) 
{ 
    super.onCreate(onsaved); 
    setContentView(R.layout.map); 
    Log.d("", "entered"); 


    map = (MapView)findViewById(R.id.mapView); 
    } 

है और यहाँ एक्सएमएल

<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=".MapsActivity" > 

<fragment 

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

</RelativeLayout> 

है और यह मेरा प्रकट

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

     <uses-sdk 
      android:minSdkVersion="14" 
      android:targetSdkVersion="17" /> 
     <!-- <permission 
       android:name="com.example.example.permission.MAPS_RECEIVE" 
       android:protectionLevel="signature"/> 
      <uses-permission android:name="com.bachelor.bond.permission.MAPS_RECEIVE"/>. --> 

      <uses-permission android:name="android.permission.INTERNET" /> 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
     <permission android:name="com.example.example.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
    <uses-permission android:name="com.example.example.permission.C2D_MESSAGE" /> 

    <!-- App receives GCM messages. --> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <!-- GCM connects to Google Services. --> 
    <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.READ_PHONE_STATE"/> 
    <!-- GCM requires a Google account. --> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <!-- Keeps the processor from sleeping when a message is received. --> 
    <uses-permission android:name="android.permission.WAKE_LOCK" 
     /> 
    <uses-permission android:name="com.example.example.permission.MAPS_RECEIVE"/> 
    <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" /> 
    <!-- Permission to vibrate --> 
     <uses-permission android:name="android.permission.VIBRATE"/> 
     <uses-permission android:name = "android.permission.ACCESS_FINE_LOCATION"/> 

     <permission 
     android:name="com.example.example.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature"></permission> 

     <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true"/> 
     <application 
      android:allowBackup="true" 
      android:icon="@drawable/ic_launcher" 
      android:label="@string/app_name"> 
      <uses-library android:name="com.google.android.maps" /> 
      <activity 
       android:name=".GPSonMap" 
       android:label="@string/app_name" 
       > <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 

        <category android:name="android.intent.category.LAUNCHER" /> 
       </intent-filter> 

      </activity> 

      <uses-library android:name="com.google.android.maps" /> 
      <intent-filter> 
     <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
     <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
     <category android:name="com.example.example" /> 
     </intent-filter> 
       <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" 
       android:permission="com.google.android.c2dm.permission.SEND" > 

    </receiver> 
    <service android:name=".GCMIntentService" /> 
    <activity android:name="Login"></activity> 

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

     </application> 

    </manifest> 

और लॉग बिल्ली उत्पादन होता है

02-15 00:42:35.257: E/AndroidRuntime(2693): FATAL EXCEPTION: main 
02-15 00:42:35.257: E/AndroidRuntime(2693): java.lang.RuntimeException: Unable to start   activity ComponentInfo{com.bachelor.bond/com.dxample.example.GPSonMap}:  android.view.InflateException: Binary XML file line #7: Error inflating class fragment 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.os.Handler.dispatchMessage(Handler.java:99) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.os.Looper.loop(Looper.java:137) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.app.ActivityThread.main(ActivityThread.java:5039) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at java.lang.reflect.Method.invoke(Method.java:511) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at dalvik.system.NativeStart.main(Native Method) 
02-15 00:42:35.257: E/AndroidRuntime(2693): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.app.Activity.setContentView(Activity.java:1881) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at com.bachelor.bond.GPSonMap.onCreate(GPSonMap.java:54) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.app.Activity.performCreate(Activity.java:5104) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  ... 11 more 
02-15 00:42:35.257: E/AndroidRuntime(2693): Caused by:   android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment  com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and  has an empty constructor that is public 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.support.v4.app.Fragment.instantiate(Fragment.java:401) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.support.v4.app.Fragment.instantiate(Fragment.java:369) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  ... 21 more 
02-15 00:42:35.257: E/AndroidRuntime(2693): Caused by: java.lang.ClassNotFoundException:  Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path:  /system/framework/com.google.android.maps.jar:/data/app/com.bachelor.bond-1.apk 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  at android.support.v4.app.Fragment.instantiate(Fragment.java:391) 
02-15 00:42:35.257: E/AndroidRuntime(2693):  ... 24 more 

एक अन्य समस्या मैं का सामना करना पड़ता है कि यह एक त्रुटि है कि यह does not को पहचान एक पैकेज का नाम com.google.android.gms तो मैं भी GoogleMap या MapFragment उदाहरण के लिए का उपयोग नहीं कर सकते होने के लिए देता है जब मैं
import com.google.android.gms.maps.MapFragment; करने की कोशिश है।

तो क्या किसी के पास उन 2 समस्याओं का कोई समाधान है?

उत्तर

3

संभवतः, आपने अपने ऐप प्रोजेक्ट में Google Play Services लाइब्रेरी प्रोजेक्ट का संदर्भ नहीं जोड़ा है। the Google Play Services SDK documentation देखें, विशेष रूप से "Google Play सेवाएं SDK का उपयोग करने के लिए प्रोजेक्ट सेट अप करने के लिए" शीर्षक वाला अनुभाग देखें।

+0

यह इतना बेवकूफ हो सकता है लेकिन मुझे वास्तव में नहीं पता कि आगे कैसे बढ़ना है। मैंने सोर्स कोड को फोल्डर ** google-play-services_lib ** में रखा है, लेकिन जब मुझे गुणों => एंड्रॉइड से इस लाइब्रेरी को आयात करना है, तो मेरे पास आयात करने के लिए कुछ भी नहीं था और जब मैंने एप्लिकेशन को एक और बार चलाया, वही समस्या अभी भी मौजूद है। –

+0

@omar: "मैंने स्रोत कोड को google-play-services_lib फ़ोल्डर में रखा है" - मुझे नहीं पता कि आप यहां क्या कह रहे हैं। ग्रहण में 'google-play-services_lib' प्रोजेक्ट आयात करें, फिर प्रोजेक्ट> गुण> एंड्रॉइड> लाइब्रेरीज़ से इसका संदर्भ जोड़ें। – CommonsWare

+0

हाँ, यह अच्छा है, लेकिन जब कोई संदर्भ जोड़ने के लिए मिलता है, जब मैं "जोड़ें" बटन पर क्लिक करता हूं, तो एक खाली सूची दिखाई देती है। –

3

मुझे पता चला कि आपने अपने कोड में कई चीजें याद की हैं।

उत्तर 1: आपका GPSonMAP.java नीचे जैसा संशोधित होना चाहिए;

public class GPSonMap extends android.support.v4.app.FragmentActivity{ 
GoogleMap googlemap; // "MapView map;" is wrong 
//MapController controller; ==> it was depreciated. 
LocationManager locationManager; 
LocationListener listener; 
PendingIntent pendingIntent ; 
Criteria criteria; 
//MapOverlay overlay; ==> it was depreciated. 
SupportMapFragment fm; // add this 


@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map); 
     Log.d("", "entered"); 


    //map = (MapView)findViewById(R.id.mapView); ==> delete it. 

    fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapView); 
    googleMap = fm.getMap(); 
    } 


} 

ऊपर, प्रेस "Ctrl + shft + (वर्ण) ओ" और कुछ आवश्यक वर्गों संशोधित करने के बाद आयात किया जाएगा।

उत्तर 2: लेआउट में आपकी एक्सएमएल फ़ाइल नीचे की तरह संशोधित की जानी चाहिए;

<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=".GPSonMap" > 

आपकी मुख्य गतिविधि नक्शा सक्रियता नहीं है, लेकिन GPSonMap है।

उत्तर 3: आपकी मैनिफ़ेस्ट फ़ाइल आपके पैकेज नाम को मैनिफेस्ट फ़ाइल में वर्णित पैकेज नाम से मेल नहीं खाती है। कृपया उसी के साथ पैकेज नाम से मेल खाते हैं।

अपने पैकेज नाम में "com.example.example" को संशोधित करें।

कुछ कोड कॉपी और पेस्ट करने के बाद, आप आवश्यक कम से कम पैकेज नाम और कक्षा का नाम देखें।

8

Android पर Google मानचित्र API v2 के माध्यम से GOOGLE मानचित्र को प्रदर्शित करने के लिए कैसे करें।

नोट कि दो मामले के सभी स्थापित करने के लिए गूगल प्ले सेवा और कई अनुमतियों और एपीआई कुंजी सहित मालसूची फ़ाइल की आवश्यकता है।

1. Google मानचित्र (समर्थन) खंडन में प्रदर्शित करें।

main.xml

<?xml version="1.0" encoding="utf-8"?> 

<!-- This can go anywhere in your layout (see other demos for some examples). --> 
<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.SupportMapFragment"/> 

MainActivity.java

/** 
* This shows how to create a simple activity with a map and a marker on the map. 
* <p> 
* Notice how we deal with the possibility that the Google Play services APK is not 
* installed/enabled/updated on a user's device. 
*/ 
public class BasicMapActivity extends android.support.v4.app.FragmentActivity { 
    /** 
    * Note that this may be null if the Google Play services APK is not available. 
    */ 
    private GoogleMap mMap; 

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

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

    /** 
    * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly 
    * installed) and the map has not already been instantiated.. This will ensure that we only ever 
    * call {@link #setUpMap()} once when {@link #mMap} is not null. 
    * <p> 
    * If it isn't installed {@link SupportMapFragment} (and 
    * {@link com.google.android.gms.maps.MapView 
    * MapView}) will show a prompt for the user to install/update the Google Play services APK on 
    * their device. 
    * <p> 
    * A user can return to this Activity after following the prompt and correctly 
    * installing/updating/enabling the Google Play services. Since the Activity may not have been 
    * completely destroyed during this process (it is likely that it would only be stopped or 
    * paused), {@link #onCreate(Bundle)} may not be called again so we should call this method in 
    * {@link #onResume()} to guarantee that it will be called. 
    */ 
    private void setUpMapIfNeeded() { 
     // Do a null check to confirm that we have not already instantiated the map. 
     if (mMap == null) { 
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
      // Check if we were successful in obtaining the map. 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 

    /** 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, we 
    * just add a marker near Africa. 
    * <p> 
    * This should only be called once and when we are sure that {@link #mMap} is not null. 
    */ 
    private void setUpMap() { 
     mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker")); 
    } 
} 

2. में (समर्थन) टुकड़ा प्रदर्शन MapView।

main.xml

<?xml version="1.0" encoding="utf-8"?> 

<!-- This can go anywhere in your layout. --> 
<com.google.android.gms.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

MainActivity.java

/** 
* This shows how to create a simple activity with a raw MapView and add a marker to it. This 
* requires forwarding all the important lifecycle methods onto MapView. 
*/ 
public class RawMapViewDemoActivity extends android.support.v4.app.FragmentActivity { 
    private MapView mMapView; 


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

     mMapView = (MapView) findViewById(R.id.map); 
     mMapView.onCreate(savedInstanceState); 


    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     mMapView.onResume(); 


    } 



    @Override 
    protected void onPause() { 
     mMapView.onPause(); 
     super.onPause(); 
    } 

    @Override 
    protected void onDestroy() { 
     mMapView.onDestroy(); 
     super.onDestroy(); 
    } 

    @Override 
    public void onLowMemory() { 
     super.onLowMemory(); 
     mMapView.onLowMemory(); 
    } 


} 
+0

कृपया, क्या आप मुझे बता सकते हैं कि मुझे जावा बिल्ड पथ में कौन सी निर्भरताओं की जांच करनी है? –

0

मैं इस समस्या थी और समय बर्बाद कर (बाल खींच हताशा का 1.5 दिन) था। फिर मैंने एक यूट्यूब वीडियो देखा जो Google Play सेवाओं को ऐप में जोड़ने के निर्देशों के माध्यम से उबाऊ चल रहा था। खैर, एसडीके प्रबंधक से एसडीके जोड़ने के बाद उस वीडियो में उन्होंने एक्लिप्स "अपडेट्स के लिए जांचें" का उपयोग किया। जादू का वह छोटा टुकड़ा बाहर चला गया और एक जार फ़ाइल डाउनलोड की गई जो एसडीके प्रबंधक नहीं करता है! उन्हें वास्तव में निर्देशों में इसे जोड़ने और लोगों को निराशा बचाने की आवश्यकता है। मैं अपने ऐप से सिर्फ Google मानचित्र को हटाने का लुत्फ उठा रहा था। मैंने 1.0 का उपयोग किया और मुझे 2.0 या डुबकी मानचित्रों को अपडेट करने की आवश्यकता थी।

संबंधित मुद्दे