Ich beginne zu lernen, Orte api. Ich habe es geschafft, eine Aktivität zu erstellen, und wenn Sie auf die Schaltfläche klicken, rendert die Ort-API-Standortauswahl mit einer Karte. Mein Problem ist, dass ich dies mit einem fest codierten LatLangBounds machen kann, was ich möchte ist, wenn ich die Karte rende an meinem aktuellen Standort starte. Ich habe dies mit Karten api getan, aber für diese Orte api bin ich verwirrt.Wie google android Plätze api an Ihrem aktuellen Standort laden
private static final int PLACE_PICKER_REQUEST = 1;
private TextView mName;
private TextView mAddress;
private TextView mAttributions;
private static final LatLngBounds BOUNDS_HARD_CODED_LOCATION = new LatLngBounds(
new LatLng(37.398160, -122.180831), new LatLng(37.430610, -121.972090));
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_place_picker);
/**
* not part of places api standard code to add back function to action bar
*/
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
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(BOUNDS_HARD_CODED_LOCATION);
Intent intent = intentBuilder.build(PlacePickerActivity.this);
startActivityForResult(intent, PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException
| GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}