Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. String apiKey = getString(R.string.places_api_key);
  2. if (!Places.isInitialized()) {
  3. Places.initialize(getApplicationContext(), apiKey);
  4. PlacesClient placesClient = Places.createClient(this);
  5. }else{
  6. Toast.makeText(PlaceAutocompleteActivity.this, "-----initialize-----", Toast.LENGTH_LONG).show();
  7. }
  8.  
  9. // Initialize the AutocompleteSupportFragment.
  10. AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
  11. getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
  12.  
  13. // PlaceFields
  14. autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG));
  15.  
  16. // autocompleteFragment.setOnPlaceSelectedListener(MapsActivity.this);
  17.  
  18. try {
  19.  
  20. autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
  21. @Override
  22. public void onPlaceSelected(@NonNull Place place) {
  23. displayLocation(place.getLatLng().latitude,place.getLatLng().longitude,place.getName());
  24. Toast.makeText(getApplicationContext(), "getName: " + place.getName() + " getLatLng: "+ place.getLatLng(), Toast.LENGTH_LONG).show();
  25.  
  26. // Intent i = Intent(this, idnow.se MainActivity.class);
  27. // i.putExtra("getLatLng",place.getLatLng());
  28. // startActivity(i);
  29. // finish();
  30. }
  31.  
  32. @Override
  33. public void onError(@NonNull Status status) {
  34. Toast.makeText(getApplicationContext(), "" + status.toString(), Toast.LENGTH_LONG).show();
  35.  
  36. }
  37.  
  38. });
  39. } catch (Exception e) {
  40. Toast.makeText(PlaceAutocompleteActivity.this, e.toString(), Toast.LENGTH_LONG).show();
  41. }
  42.  
  43. autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement