*https://codelabs.developers.google.com/codelabs/fire-place/index.html?index=..%2F..%2Findex#8
Last active
September 16, 2018 17:13
-
-
Save OrenBochman/f3f1f0af2ddc2d207d8de523cac2084f to your computer and use it in GitHub Desktop.
places_api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.google.checkout; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.content.pm.PackageManager; | |
import android.location.Location; | |
import android.support.v4.app.ActivityCompat; | |
import android.support.v4.app.FragmentActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.view.ViewTreeObserver; | |
import android.widget.Button; | |
import android.widget.Toast; | |
import com.google.android.gms.common.GoogleApiAvailability; | |
import com.google.android.gms.common.GooglePlayServicesNotAvailableException; | |
import com.google.android.gms.common.GooglePlayServicesRepairableException; | |
import com.google.android.gms.common.api.GoogleApiClient; | |
import com.google.android.gms.location.places.Place; | |
import com.google.android.gms.location.places.Places; | |
import com.google.android.gms.location.places.ui.PlacePicker; | |
import com.google.android.gms.maps.CameraUpdateFactory; | |
import com.google.android.gms.maps.GoogleMap; | |
import com.google.android.gms.maps.OnMapReadyCallback; | |
import com.google.android.gms.maps.SupportMapFragment; | |
import com.google.android.gms.maps.model.LatLng; | |
import com.google.android.gms.maps.model.LatLngBounds; | |
import com.google.android.gms.maps.model.MarkerOptions; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { | |
private GoogleMap mMap; | |
private LatLngBounds.Builder mBounds = new LatLngBounds.Builder(); | |
private GoogleApiClient mGoogleApiClient; | |
List<Place> places = new ArrrayList<Place>(); | |
private void addPointToViewPort(LatLng newPoint) { | |
mBounds.include(newPoint); | |
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(mBounds.build(), | |
findViewById(R.id.checkout_button).getHeight())); | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_maps); | |
// Obtain the SupportMapFragment and get notified when the map is ready to be used. | |
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() | |
.findFragmentById(R.id.map); | |
mapFragment.getMapAsync(this); | |
// Set up the API client for Places API | |
mGoogleApiClient = new GoogleApiClient.Builder(this) | |
.addApi(Places.GEO_DATA_API) | |
.build(); | |
mGoogleApiClient.connect(); | |
} | |
/** | |
* Manipulates the map once available. | |
* This callback is triggered when the map is ready to be used. | |
* This is where we can add markers or lines, add listeners or move the camera. In this case, | |
* we just add a marker near Sydney, Australia. | |
* If Google Play services is not installed on the device, the user will be prompted to install | |
* it inside the SupportMapFragment. This method will only be triggered once the user has | |
* installed Google Play services and returned to the app. | |
*/ | |
@Override | |
public void onMapReady(GoogleMap googleMap) { | |
final Button button = (Button) findViewById(R.id.checkout_button); | |
button.getViewTreeObserver().addOnGlobalLayoutListener( | |
new ViewTreeObserver.OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
mMap.setPadding(0, button.getHeight(), 0, 0); | |
} | |
} | |
); | |
mMap = googleMap; | |
// Add a marker in Sydney and move the camera | |
LatLng sydney = new LatLng(32.108333, 34.8555); | |
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in TelAviv")); | |
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); | |
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { | |
// TODO: Consider calling | |
// ActivityCompat#requestPermissions | |
// here to request the missing permissions, and then overriding | |
// public void onRequestPermissionsResult(int requestCode, String[] permissions, | |
// int[] grantResults) | |
// to handle the case where the user grants the permission. See the documentation | |
// for ActivityCompat#requestPermissions for more details. | |
return; | |
} | |
mMap.setMyLocationEnabled(true); | |
mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { | |
@Override | |
public void onMyLocationChange(Location location) { | |
LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); | |
addPointToViewPort(ll); | |
places.add(ll); | |
// we only want to grab the location once, to allow the user to pan and zoom freely. | |
mMap.setOnMyLocationChangeListener(null); | |
} | |
}); | |
} | |
private static final int REQUEST_PLACE_PICKER = 1; | |
public void checkOut(View view) { | |
try { | |
PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder(); | |
Intent intent = intentBuilder.build(this); | |
//this request the data from the places api using an intent | |
startActivityForResult(intent, REQUEST_PLACE_PICKER); | |
} catch (GooglePlayServicesRepairableException e) { | |
GoogleApiAvailability.getInstance().getErrorDialog(this, e.getConnectionStatusCode(), | |
REQUEST_PLACE_PICKER); | |
} catch (GooglePlayServicesNotAvailableException e) { | |
Toast.makeText(this, "Please install Google Play Services!", Toast.LENGTH_LONG).show(); | |
} | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if (requestCode == REQUEST_PLACE_PICKER) { | |
if (resultCode == Activity.RESULT_OK) { | |
Place place = PlacePicker.getPlace(data, this); | |
mMap.addMarker(new MarkerOptions().position(place.getLatLng())); | |
} else if (resultCode == PlacePicker.RESULT_ERROR) { | |
Toast.makeText(this, "Places API failure! Check that the API is enabled for your key", Toast.LENGTH_LONG).show(); | |
} | |
} else { | |
super.onActivityResult(requestCode, resultCode, data); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.google.checkout; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.content.pm.PackageManager; | |
import android.location.Location; | |
import android.support.v4.app.ActivityCompat; | |
import android.support.v4.app.FragmentActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.view.ViewTreeObserver; | |
import android.widget.Button; | |
import android.widget.Toast; | |
import com.firebase.client.ChildEventListener; | |
import com.firebase.client.DataSnapshot; | |
import com.firebase.client.Firebase; | |
import com.firebase.client.FirebaseError; | |
import com.firebase.client.ServerValue; | |
import com.google.android.gms.common.GoogleApiAvailability; | |
import com.google.android.gms.common.GooglePlayServicesNotAvailableException; | |
import com.google.android.gms.common.GooglePlayServicesRepairableException; | |
import com.google.android.gms.common.api.GoogleApiClient; | |
import com.google.android.gms.common.api.ResultCallback; | |
import com.google.android.gms.location.places.Place; | |
import com.google.android.gms.location.places.PlaceBuffer; | |
import com.google.android.gms.location.places.Places; | |
import com.google.android.gms.location.places.ui.PlacePicker; | |
import com.google.android.gms.maps.CameraUpdateFactory; | |
import com.google.android.gms.maps.GoogleMap; | |
import com.google.android.gms.maps.OnMapReadyCallback; | |
import com.google.android.gms.maps.SupportMapFragment; | |
import com.google.android.gms.maps.model.LatLng; | |
import com.google.android.gms.maps.model.LatLngBounds; | |
import com.google.android.gms.maps.model.MarkerOptions; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, ChildEventListener { | |
private GoogleMap mMap; | |
private LatLngBounds.Builder mBounds = new LatLngBounds.Builder(); | |
private GoogleApiClient mGoogleApiClient; | |
//firebase | |
private static final String FIREBASE_URL = "https://places-214914.firebaseio.com/"; | |
private static final String FIREBASE_ROOT_NODE = "checkouts"; | |
private Firebase mFirebase; | |
private void addPointToViewPort(LatLng newPoint) { | |
mBounds.include(newPoint); | |
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(mBounds.build(), | |
findViewById(R.id.checkout_button).getHeight())); | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_maps); | |
// Set up Firebase | |
Firebase.setAndroidContext(this); | |
mFirebase = new Firebase(FIREBASE_URL); | |
mFirebase.child(FIREBASE_ROOT_NODE).addChildEventListener(this); | |
// Obtain the SupportMapFragment and get notified when the map is ready to be used. | |
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() | |
.findFragmentById(R.id.map); | |
mapFragment.getMapAsync(this); | |
// Set up the API client for Places API | |
mGoogleApiClient = new GoogleApiClient.Builder(this) | |
.addApi(Places.GEO_DATA_API) | |
.build(); | |
mGoogleApiClient.connect(); | |
} | |
/** | |
* Manipulates the map once available. | |
* This callback is triggered when the map is ready to be used. | |
* This is where we can add markers or lines, add listeners or move the camera. In this case, | |
* we just add a marker near Sydney, Australia. | |
* If Google Play services is not installed on the device, the user will be prompted to install | |
* it inside the SupportMapFragment. This method will only be triggered once the user has | |
* installed Google Play services and returned to the app. | |
*/ | |
@Override | |
public void onMapReady(GoogleMap googleMap) { | |
final Button button = (Button) findViewById(R.id.checkout_button); | |
button.getViewTreeObserver().addOnGlobalLayoutListener( | |
new ViewTreeObserver.OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
mMap.setPadding(0, button.getHeight(), 0, 0); | |
} | |
} | |
); | |
mMap = googleMap; | |
// Add a marker in Sydney and move the camera | |
LatLng telAviv = new LatLng(32.108333, 34.8555); | |
mMap.addMarker(new MarkerOptions().position(telAviv).title("Marker in TelAviv")); | |
mMap.moveCamera(CameraUpdateFactory.newLatLng(telAviv)); | |
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { | |
// TODO: Consider calling | |
// ActivityCompat#requestPermissions | |
// here to request the missing permissions, and then overriding | |
// public void onRequestPermissionsResult(int requestCode, String[] permissions, | |
// int[] grantResults) | |
// to handle the case where the user grants the permission. See the documentation | |
// for ActivityCompat#requestPermissions for more details. | |
return; | |
} | |
mMap.setMyLocationEnabled(true); | |
mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { | |
@Override | |
public void onMyLocationChange(Location location) { | |
LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); | |
addPointToViewPort(ll); | |
// we only want to grab the location once, to allow the user to pan and zoom freely. | |
mMap.setOnMyLocationChangeListener(null); | |
} | |
}); | |
} | |
private static final int REQUEST_PLACE_PICKER = 1; | |
public void checkOut(View view) { | |
try { | |
PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder(); | |
Intent intent = intentBuilder.build(this); | |
//this request the data from the places api using an intent | |
startActivityForResult(intent, REQUEST_PLACE_PICKER); | |
} catch (GooglePlayServicesRepairableException e) { | |
GoogleApiAvailability.getInstance().getErrorDialog(this, e.getConnectionStatusCode(), | |
REQUEST_PLACE_PICKER); | |
} catch (GooglePlayServicesNotAvailableException e) { | |
Toast.makeText(this, "Please install Google Play Services!", Toast.LENGTH_LONG).show(); | |
} | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if (requestCode == REQUEST_PLACE_PICKER) { | |
if (resultCode == Activity.RESULT_OK) { | |
Place place = PlacePicker.getPlace(data, this); | |
Map<String, Object> checkoutData = new HashMap<>(); | |
checkoutData.put("time", ServerValue.TIMESTAMP); | |
mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId()).setValue(checkoutData); | |
// mMap.addMarker(new MarkerOptions().position(place.getLatLng())); | |
} else if (resultCode == PlacePicker.RESULT_ERROR) { | |
Toast.makeText(this, "Places API failure! Check the API is enabled for your key", | |
Toast.LENGTH_LONG).show(); | |
} | |
} else { | |
super.onActivityResult(requestCode, resultCode, data); | |
} | |
} | |
@Override | |
public void onChildAdded(DataSnapshot dataSnapshot, String s) { | |
String placeId = dataSnapshot.getKey(); | |
if (placeId != null) { | |
Places.GeoDataApi | |
.getPlaceById(mGoogleApiClient, placeId) | |
.setResultCallback(new ResultCallback<PlaceBuffer>() { | |
@Override | |
public void onResult(PlaceBuffer places) { | |
LatLng location = places.get(0).getLatLng(); | |
addPointToViewPort(location); | |
Log.i("MapActivity", "onResult: new location "+location.toString()); | |
mMap.addMarker(new MarkerOptions().position(location)); | |
places.release(); | |
} | |
} | |
); | |
} | |
} | |
@Override | |
public void onChildChanged(DataSnapshot dataSnapshot, String s) { | |
} | |
@Override | |
public void onChildRemoved(DataSnapshot dataSnapshot) { | |
} | |
@Override | |
public void onChildMoved(DataSnapshot dataSnapshot, String s) { | |
} | |
@Override | |
public void onCancelled(FirebaseError firebaseError) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.google.checkout; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.content.pm.PackageManager; | |
import android.location.Location; | |
import android.support.v4.app.ActivityCompat; | |
import android.support.v4.app.FragmentActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.view.ViewTreeObserver; | |
import android.widget.Button; | |
import android.widget.Toast; | |
import com.firebase.client.ChildEventListener; | |
import com.firebase.client.DataSnapshot; | |
import com.firebase.client.Firebase; | |
import com.firebase.client.FirebaseError; | |
import com.firebase.client.ServerValue; | |
import com.google.android.gms.common.GoogleApiAvailability; | |
import com.google.android.gms.common.GooglePlayServicesNotAvailableException; | |
import com.google.android.gms.common.GooglePlayServicesRepairableException; | |
import com.google.android.gms.common.api.GoogleApiClient; | |
import com.google.android.gms.common.api.ResultCallback; | |
import com.google.android.gms.location.places.Place; | |
import com.google.android.gms.location.places.PlaceBuffer; | |
import com.google.android.gms.location.places.Places; | |
import com.google.android.gms.location.places.ui.PlacePicker; | |
import com.google.android.gms.maps.CameraUpdateFactory; | |
import com.google.android.gms.maps.GoogleMap; | |
import com.google.android.gms.maps.OnMapReadyCallback; | |
import com.google.android.gms.maps.SupportMapFragment; | |
import com.google.android.gms.maps.model.LatLng; | |
import com.google.android.gms.maps.model.LatLngBounds; | |
import com.google.android.gms.maps.model.MarkerOptions; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, ChildEventListener { | |
private GoogleMap mMap; | |
private LatLngBounds.Builder mBounds = new LatLngBounds.Builder(); | |
private GoogleApiClient mGoogleApiClient; | |
//firebase | |
private static final String FIREBASE_URL = "https://places-214914.firebaseio.com/"; | |
private static final String FIREBASE_ROOT_NODE = "checkouts"; | |
private Firebase mFirebase; | |
private void addPointToViewPort(LatLng newPoint) { | |
mBounds.include(newPoint); | |
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(mBounds.build(), | |
findViewById(R.id.checkout_button).getHeight())); | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_maps); | |
// Set up Firebase | |
Firebase.setAndroidContext(this); | |
mFirebase = new Firebase(FIREBASE_URL); | |
mFirebase.child(FIREBASE_ROOT_NODE).addChildEventListener(this); | |
// Obtain the SupportMapFragment and get notified when the map is ready to be used. | |
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() | |
.findFragmentById(R.id.map); | |
mapFragment.getMapAsync(this); | |
// Set up the API client for Places API | |
mGoogleApiClient = new GoogleApiClient.Builder(this) | |
.addApi(Places.GEO_DATA_API) | |
.build(); | |
mGoogleApiClient.connect(); | |
} | |
/** | |
* Manipulates the map once available. | |
* This callback is triggered when the map is ready to be used. | |
* This is where we can add markers or lines, add listeners or move the camera. In this case, | |
* we just add a marker near Sydney, Australia. | |
* If Google Play services is not installed on the device, the user will be prompted to install | |
* it inside the SupportMapFragment. This method will only be triggered once the user has | |
* installed Google Play services and returned to the app. | |
*/ | |
@Override | |
public void onMapReady(GoogleMap googleMap) { | |
final Button button = (Button) findViewById(R.id.checkout_button); | |
button.getViewTreeObserver().addOnGlobalLayoutListener( | |
new ViewTreeObserver.OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
mMap.setPadding(0, button.getHeight(), 0, 0); | |
} | |
} | |
); | |
mMap = googleMap; | |
// Add a marker in Sydney and move the camera | |
LatLng telAviv = new LatLng(32.108333, 34.8555); | |
mMap.addMarker(new MarkerOptions().position(telAviv).title("Marker in TelAviv")); | |
mMap.moveCamera(CameraUpdateFactory.newLatLng(telAviv)); | |
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { | |
// TODO: Consider calling | |
// ActivityCompat#requestPermissions | |
// here to request the missing permissions, and then overriding | |
// public void onRequestPermissionsResult(int requestCode, String[] permissions, | |
// int[] grantResults) | |
// to handle the case where the user grants the permission. See the documentation | |
// for ActivityCompat#requestPermissions for more details. | |
return; | |
} | |
mMap.setMyLocationEnabled(true); | |
mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { | |
@Override | |
public void onMyLocationChange(Location location) { | |
LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); | |
addPointToViewPort(ll); | |
// we only want to grab the location once, to allow the user to pan and zoom freely. | |
mMap.setOnMyLocationChangeListener(null); | |
} | |
}); | |
} | |
private static final int REQUEST_PLACE_PICKER = 1; | |
public void checkOut(View view) { | |
try { | |
PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder(); | |
Intent intent = intentBuilder.build(this); | |
//this request the data from the places api using an intent | |
startActivityForResult(intent, REQUEST_PLACE_PICKER); | |
} catch (GooglePlayServicesRepairableException e) { | |
GoogleApiAvailability.getInstance().getErrorDialog(this, e.getConnectionStatusCode(), | |
REQUEST_PLACE_PICKER); | |
} catch (GooglePlayServicesNotAvailableException e) { | |
Toast.makeText(this, "Please install Google Play Services!", Toast.LENGTH_LONG).show(); | |
} | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if (requestCode == REQUEST_PLACE_PICKER) { | |
if (resultCode == Activity.RESULT_OK) { | |
Place place = PlacePicker.getPlace(data, this); | |
Map<String, Object> checkoutData = new HashMap<>(); | |
checkoutData.put("time", ServerValue.TIMESTAMP); | |
mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId()).setValue(checkoutData); | |
// mMap.addMarker(new MarkerOptions().position(place.getLatLng())); | |
} else if (resultCode == PlacePicker.RESULT_ERROR) { | |
Toast.makeText(this, "Places API failure! Check the API is enabled for your key", | |
Toast.LENGTH_LONG).show(); | |
} | |
} else { | |
super.onActivityResult(requestCode, resultCode, data); | |
} | |
} | |
@Override | |
public void onChildAdded(DataSnapshot dataSnapshot, String s) { | |
String placeId = dataSnapshot.getKey(); | |
if (placeId != null) { | |
Places.GeoDataApi | |
.getPlaceById(mGoogleApiClient, placeId) | |
.setResultCallback(new ResultCallback<PlaceBuffer>() { | |
@Override | |
public void onResult(PlaceBuffer places) { | |
LatLng location = places.get(0).getLatLng(); | |
addPointToViewPort(location); | |
Log.i("MapActivity", "onResult: new location "+location.toString()); | |
mMap.addMarker(new MarkerOptions().position(location)); | |
places.release(); | |
} | |
} | |
); | |
} | |
} | |
@Override | |
public void onChildChanged(DataSnapshot dataSnapshot, String s) { | |
} | |
@Override | |
public void onChildRemoved(DataSnapshot dataSnapshot) { | |
} | |
@Override | |
public void onChildMoved(DataSnapshot dataSnapshot, String s) { | |
} | |
@Override | |
public void onCancelled(FirebaseError firebaseError) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
buildscript { | |
repositories { | |
google() | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:3.1.4' | |
classpath 'com.google.gms:google-services:4.0.1' | |
// NOTE: Do not place your application dependencies here; they belong | |
// in the individual module build.gradle files | |
} | |
} | |
allprojects { | |
repositories { | |
google() | |
jcenter() | |
} | |
} | |
task clean(type: Delete) { | |
delete rootProject.buildDir | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 28 | |
defaultConfig { | |
applicationId "io.google.checkout" | |
minSdkVersion 19 | |
targetSdkVersion 28 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
packagingOptions { | |
exclude 'META-INF/LICENSE' | |
exclude 'META-INF/NOTICE' | |
} | |
} | |
dependencies { | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation 'androidx.appcompat:appcompat:1.0.0-rc02' | |
implementation "androidx.room:room-runtime:2.0.0-rc01" | |
annotationProcessor "androidx.room:room-compiler:2.0.0-rc01" | |
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-rc01" | |
implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0-rc02' | |
implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0-rc02' | |
implementation 'androidx.fragment:fragment:1.0.0-rc02' | |
testImplementation 'junit:junit:4.12' | |
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' | |
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' | |
implementation 'com.google.gms:google-services:4.0.1' //play services | |
implementation 'com.google.android.gms:play-services-places:15.0.1' //places | |
implementation 'com.firebase:firebase-client-android:2.2.4' //firebase | |
implementation 'com.google.firebase:firebase-core:16.0.3' //firebase | |
implementation 'com.google.android.gms:play-services-location:15.0.1' //location | |
implementation 'com.google.android.gms:play-services-maps:15.0.1' | |
} | |
apply plugin: 'com.google.gms.google-services' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mGeoDataClient.getPlaceById(placeId).addOnCompleteListener(new OnCompleteListener<PlaceBufferResponse>() { | |
@Override | |
public void onComplete(@NonNull Task<PlaceBufferResponse> task) { | |
if (task.isSuccessful()) { | |
PlaceBufferResponse places = task.getResult(); | |
Place myPlace = places.get(0); | |
Log.i(TAG, "Place found: " + myPlace.getName()); | |
places.release(); | |
} else { | |
Log.e(TAG, "Place not found."); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void findPlace(View view) { | |
try { | |
Intent intent = | |
new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) | |
.setFilter(typeFilter) | |
.build(this); | |
startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE); | |
} catch (GooglePlayServicesRepairableException e) { | |
// TODO: Handle the error. | |
} catch (GooglePlayServicesNotAvailableException e) { | |
// TODO: Handle the error. | |
} | |
} | |
// A place has been received; use requestCode to track the request. | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) { | |
if (resultCode == RESULT_OK) { | |
Place place = PlaceAutocomplete.getPlace(this, data); | |
Log.i(TAG, "Place: " + place.getName()); | |
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { | |
Status status = PlaceAutocomplete.getStatus(this, data); | |
// TODO: Handle the error. | |
Log.i(TAG, status.getStatusMessage()); | |
} else if (resultCode == RESULT_CANCELED) { | |
// The user canceled the operation. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment