2017-11-09 4 views
2

Googleの場所を開くはずのボタンをクリックしてアクティビティの意図を作成していますが、本当に速く閉じて、選択されていない場所を示してメインに戻りますもう一度クリックすると何も起こりません。アンドロイド - Googleプレイスが1秒後に地図を開く

apiキーに接続された正しいSHA1フィンガープリントであることを確認しました。

結果コードがある2

それはこの1つ前に、以前の活動で働いていたが、私は、私が代わりにボタンをクリックしたときに開くようにそれを必要とし、今私は意図として、この新しい活動を開こうとするとそれは動作しません。

public class MapActivity extends AppCompatActivity { 

int PLACE_PICKER_REQUEST = 1; 
int status; 

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

    status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); 
    if (status != ConnectionResult.SUCCESS) { 
     if (GooglePlayServicesUtil.isUserRecoverableError(status)) { 
      GooglePlayServicesUtil.getErrorDialog(status, this, 
        100).show(); 
     } 
    } 
    if (status == ConnectionResult.SUCCESS) { 
     int PLACE_PICKER_REQUEST = 199; 
     PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); 
     Context context = this; 
     try { 
      startActivityForResult(builder.build(context), PLACE_PICKER_REQUEST); 
     } catch (GooglePlayServicesRepairableException e) { 
      e.printStackTrace(); 
     } catch (GooglePlayServicesNotAvailableException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    System.out.println("Result code: " + resultCode); 
    System.out.println("Request code: " + requestCode); 
    if (requestCode == 100) { 
     status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); 
    } 
    if (requestCode == 199) { 

     //process Intent...... 
     if (data != null) { 
      Place place = PlacePicker.getPlace(data, this); 
      String toastMsg = String.format("Place: %s", place.getName()); 
      Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show(); 
     } else { 
      String toastMsg = ("No location selected."); 
      Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show(); 
     } 

    } 
} 

}

これはしようと、私はあなたのためにその出来事がgetPlace

の古い方法を使用していると思うマップ

public void onClick(View view) { 
     Intent i = new Intent(this, MapActivity.class); 
     startActivity(i); 
    } 

答えて

1

に新しい目的を作成する意図からです引数を次のように変更して引数を入れ替えます。

Place place = PlacePicker.getPlace(data, this); 

GoogleはデベロッパーコンソールでAPIを配置有効にしAndroidManifest

<meta-data 
    android:name="com.google.android.geo.API_KEY" 
    android:value="ADD_YOUR_API_KEY_HERE" /> 

更新#にこれらの行を追加します

Place place = PlacePicker.getPlace(getContext(), data); 

更新#2

へ3

検索した後、同じ問題がある他の人がいるようです。これらのリンクを見てください:

https://github.com/zhangtaii/react-native-google-place-picker/issues/21

https://www.codesd.com/item/google-placepicker-closes-immediately-after-launch-with-result-code-2.html

https://github.com/googlesamples/android-play-places/issues/13

+0

それはエラーになります:( –

+0

エラーが何であるPlacePickerで – Tirolel

+0

が –

関連する問題