0

Ich arbeite an einem Projekt mit der API google place. Ich verwende PlacePicker und ich verfolge mein Telefon, um PlacePicker zu starten, wo ich bin. Dies ist meine Klasse mit Ort und PlacePicker.PlacePicker startet nicht mit Standort

public class ProspectionActivity extends BaseActivity { 
    private static final int PLACE_PICKER_REQUEST = 1; 
    private TextView mName; 
    private TextView mAddress; 
    private TextView mAttributions; 
    private static final LatLngBounds BOUNDS_MOUNTAIN_VIEW = new LatLngBounds(
      new LatLng(48.8453849, 2.328134900000009), new LatLng(48.866667, 2.333333)); 
        public double latitude; 
    public double longitude; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

    FrameLayout contentFrameLayout = (FrameLayout) findViewById(R.id.content_frame); //Remember this is the FrameLayout area within your activity_base.xml 
    getLayoutInflater().inflate(R.layout.activity_prospection, contentFrameLayout); 
    LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); 
    boolean enabled = service 
      .isProviderEnabled(LocationManager.GPS_PROVIDER); 

    if (!enabled) { 
     Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
     startActivity(intent); 
    } 

    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    if (location!=null){ 
     longitude = location.getLongitude(); 
     latitude = location.getLatitude(); 
     final LatLngBounds coordinate = new LatLngBounds(new LatLng(latitude-0.000005, longitude-0.000005),new LatLng(latitude+0.000005,longitude+0.000005)); 
     mName = (TextView) findViewById(R.id.textView); 
     mAddress = (TextView) findViewById(R.id.textView2); 
     mAttributions = (TextView) findViewById(R.id.textView3); 
     Button pickerButton = (Button) findViewById(R.id.pickerButton); 
     pickerButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       try { 
        PlacePicker.IntentBuilder intentBuilder = 
          new PlacePicker.IntentBuilder(); 
        intentBuilder.setLatLngBounds(coordinate); 
        Intent intent = intentBuilder.build(ProspectionActivity.this); 
        startActivityForResult(intent, PLACE_PICKER_REQUEST); 

       } catch (GooglePlayServicesRepairableException 
         | GooglePlayServicesNotAvailableException e) { 
        e.printStackTrace(); 
       } 
      } 
     }); 
    } 

} 

@Override 
protected void onActivityResult(int requestCode, 
           int resultCode, Intent data) { 

    if (requestCode == PLACE_PICKER_REQUEST 
      && resultCode == Activity.RESULT_OK) { 

     final Place place = PlacePicker.getPlace(this, data); 
     final CharSequence name = place.getName(); 
     final CharSequence address = place.getAddress(); 
     String attributions = (String) place.getAttributions(); 
     if (attributions == null) { 
      attributions = ""; 
     } 

     mName.setText(name); 
     mAddress.setText(address); 
     mAttributions.setText(Html.fromHtml(attributions)); 

    } else { 
     super.onActivityResult(requestCode, resultCode, data); 
    } 
} 

} `
Leider, wenn ich auf die Schaltfläche klicken Sie auf die PlacePicker zu starten. Nichts passiert. Wenn mir bitte jemand helfen kann.

Hier ist mein Manifest

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 

    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".BaseActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar" /> 
    <activity 
     android:name=".ProspectionActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar" /> 
    <meta-data 

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

</application> 

Antwort

1

Es könnte nützlich sein, um Fehler in logcat Ausgang zu suchen, die Ihnen sagen, was los ist.

Mit Blick auf Ihr Manifest sehe ich, dass Sie nicht die ACCESS_FINE_LOCATION Erlaubnis angefordert haben. Dies könnte das Problem sein. Versuchen Sie Folgendes hinzuzufügen:

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

Vielen Dank. Das Problem war, dass wenn das Telefon keinen Standort findet, nichts gestartet wird. –