2017-04-10 6 views
0

任意の結果を返しません。ジオデータAPIは、私がPlaces.GeoDataApiにplace_idを渡すことで、場所を取得しようとしていますが、それは何も返していないと私はplace_idが正しいことを確信している

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

    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addApi(Places.GEO_DATA_API) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this).build(); 

    String placeId = "ChIJja4QaeH0GjkRKK5cBjTfKQo"; 

    Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId) 
      .setResultCallback(new ResultCallback<PlaceBuffer>() { 
       @Override 
       public void onResult(@NonNull PlaceBuffer places) { 
        if(places.getStatus().isSuccess() && places.getCount()>0){ 
         final Place myPlace = places.get(0); 
         Log.i(String.valueOf(MainActivity.this), 
           "Place found: " + myPlace.getName() + "\n Address: " + myPlace.getAddress()); 
        } else { 
         Log.i(String.valueOf(MainActivity.this),"Place not found!"); 
        } 
        places.release(); 
       } 
      }); 
} 

編集:追加のmanifest.xmlファイル

のAndroidManifest.xml

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

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <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.geo.API_KEY" 
     android:value="MY_API_KEY"/> 

</application> 

+0

あなたのマニフェストを投稿... – rafsanahmad007

+0

投稿された@ rafsanahmad007 –

+1

@GautamHans公開するAPIキーを共有することはお勧めできませんそれを非表示にしてください... !!!! –

答えて

1

コードは、1つは、私はimplemented..exceptことは非常に似ています一例を挙げると。

あなたのコードでmGoogleApiClient.connect();

に電話をするのを忘れた:

mGoogleApiClient = new GoogleApiClient.Builder(this) 
     .addApi(Places.GEO_DATA_API) 
     .addConnectionCallbacks(this) 
     .addOnConnectionFailedListener(this).build(); 

mGoogleApiClient.connect(); //add this 

//now call the placeID codes Result callback 

編集

条件にわずかなアップデートを:

if(places.getStatus().isSuccess()){ 
    final Place myPlace = places.get(0); 
    Log.i(String.valueOf(MainActivity.this), 
      "Place found: " + myPlace.getName() + "\n Address: " + myPlace.getAddress()); 
} else { 
    Log.i(String.valueOf(MainActivity.this),"Place not found!"); 
} 
+0

ありがとうございます。出来た! :) place_idが正しいにもかかわらず、Place Not Foundがログに記録されています。 –

+0

それはそう、私は 文字列placeId =「ChIJja4QaeH0GjkRKK5cBjTfKQo」のようなplaceIdを指定していますから...指定されたplaceID .. – rafsanahmad007

+0

場所を返します。 それでも場所が見つからない。 私は それが「Virk病院とマタニティホーム」を返す必要があります あまりにも「ChIJfapwfcT0GjkR6aj2WIaRdIk」別のIDを試してみたが、それは他の部分になるだろう。 –

関連する問題