SlideShare a Scribd company logo
Creating an Uber Clone - Part XVII
WebServices from the Device?
✦I took a shortcut and chose to invoke the Google
webservices from the device
✦The reason I did this is that I want to teach mobile
programming not server programming
✦Google API keys would be more secure in the server
✦We can cache common queries in the server and
reduce API costs
✦We can monitor the calls sent out and identify trends
✦We can instantly switch providers without shipping a
new version of the app
© Codename One 2017 all rights reserved
Googles GIS Services
✦Geocoding
✦Reverse Geocoding
✦Directions
✦Places Autocomplete
© Codename One 2017 all rights reserved
public static final String GOOGLE_DIRECTIONS_KEY = "----";
public static final String GOOGLE_GEOCODING_KEY = "----";
public static final String GOOGLE_PLACES_KEY = "----";
New Fields in Globals
https://maps.googleapis.com/maps/api/geocode/json?
latlng=40.714224,-73.961452&key=YOUR_API_KEY
Reverse Geocoding
{
"results" : [
{
"address_components" : [
{
"long_name" : "277",
"short_name" : "277",
"types" : [ "street_number" ]
},
{
"long_name" : "Bedford Avenue",
"short_name" : "Bedford Ave",
"types" : [ "route" ]
},
... trimmed ...
],
"formatted_address" : "277 Bedford Avenue, Brooklyn, NY 11211, USA",
"geometry" : {
"location" : {
"lat" : 40.714232,
"lng" : -73.9612889
Reverse Geocoding - Result
{
"results" : [
{
"address_components" : [
{
"long_name" : "277",
"short_name" : "277",
"types" : [ "street_number" ]
},
{
"long_name" : "Bedford Avenue",
"short_name" : "Bedford Ave",
"types" : [ "route" ]
},
... trimmed ...
],
"formatted_address" : "277 Bedford Avenue, Brooklyn, NY 11211, USA",
"geometry" : {
"location" : {
"lat" : 40.714232,
"lng" : -73.9612889
Reverse Geocoding - Result
public class SearchService {
private static ConnectionRequest lastLocationRequest;
public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) {
if(l == null) {
return;
}
if(lastLocationRequest != null) {
lastLocationRequest.kill();
}
lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json").
queryParam("latlng", l.getLatitude() + "," + l.getLongitude()).
queryParam("key", GOOGLE_GEOCODING_KEY).
queryParam("language", "en").
queryParam("result_type", "street_address|point_of_interest").
getAsJsonMap(callbackMap -> {
Map data = callbackMap.getResponseData();
if(data != null) {
List results = (List)data.get("results");
if(results != null && results.size() > 0) {
Map firstResult = (Map)results.get(0);
name.onSucess((String)firstResult.get("formatted_address"));
}
}
});
}
SearchService
public class SearchService {
private static ConnectionRequest lastLocationRequest;
public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) {
if(l == null) {
return;
}
if(lastLocationRequest != null) {
lastLocationRequest.kill();
}
lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json").
queryParam("latlng", l.getLatitude() + "," + l.getLongitude()).
queryParam("key", GOOGLE_GEOCODING_KEY).
queryParam("language", "en").
queryParam("result_type", "street_address|point_of_interest").
getAsJsonMap(callbackMap -> {
Map data = callbackMap.getResponseData();
if(data != null) {
List results = (List)data.get("results");
if(results != null && results.size() > 0) {
Map firstResult = (Map)results.get(0);
name.onSucess((String)firstResult.get("formatted_address"));
}
}
});
}
SearchService
public class SearchService {
private static ConnectionRequest lastLocationRequest;
public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) {
if(l == null) {
return;
}
if(lastLocationRequest != null) {
lastLocationRequest.kill();
}
lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json").
queryParam("latlng", l.getLatitude() + "," + l.getLongitude()).
queryParam("key", GOOGLE_GEOCODING_KEY).
queryParam("language", "en").
queryParam("result_type", "street_address|point_of_interest").
getAsJsonMap(callbackMap -> {
Map data = callbackMap.getResponseData();
if(data != null) {
List results = (List)data.get("results");
if(results != null && results.size() > 0) {
Map firstResult = (Map)results.get(0);
name.onSucess((String)firstResult.get("formatted_address"));
}
}
});
}
SearchService
public class SearchService {
private static ConnectionRequest lastLocationRequest;
public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) {
if(l == null) {
return;
}
if(lastLocationRequest != null) {
lastLocationRequest.kill();
}
lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json").
queryParam("latlng", l.getLatitude() + "," + l.getLongitude()).
queryParam("key", GOOGLE_GEOCODING_KEY).
queryParam("language", "en").
queryParam("result_type", "street_address|point_of_interest").
getAsJsonMap(callbackMap -> {
Map data = callbackMap.getResponseData();
if(data != null) {
List results = (List)data.get("results");
if(results != null && results.size() > 0) {
Map firstResult = (Map)results.get(0);
name.onSucess((String)firstResult.get("formatted_address"));
}
}
});
}
SearchService
public class SearchService {
private static ConnectionRequest lastLocationRequest;
public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) {
if(l == null) {
return;
}
if(lastLocationRequest != null) {
lastLocationRequest.kill();
}
lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json").
queryParam("latlng", l.getLatitude() + "," + l.getLongitude()).
queryParam("key", GOOGLE_GEOCODING_KEY).
queryParam("language", "en").
queryParam("result_type", "street_address|point_of_interest").
getAsJsonMap(callbackMap -> {
Map data = callbackMap.getResponseData();
if(data != null) {
List results = (List)data.get("results");
if(results != null && results.size() > 0) {
Map firstResult = (Map)results.get(0);
name.onSucess((String)firstResult.get("formatted_address"));
}
}
});
}
SearchService
public class SearchService {
private static ConnectionRequest lastLocationRequest;
public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) {
if(l == null) {
return;
}
if(lastLocationRequest != null) {
lastLocationRequest.kill();
}
lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json").
queryParam("latlng", l.getLatitude() + "," + l.getLongitude()).
queryParam("key", GOOGLE_GEOCODING_KEY).
queryParam("language", "en").
queryParam("result_type", "street_address|point_of_interest").
getAsJsonMap(callbackMap -> {
Map data = callbackMap.getResponseData();
if(data != null) {
List results = (List)data.get("results");
if(results != null && results.size() > 0) {
Map firstResult = (Map)results.get(0);
name.onSucess((String)firstResult.get("formatted_address"));
}
}
});
}
SearchService
public class SearchService {
private static ConnectionRequest lastLocationRequest;
public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) {
if(l == null) {
return;
}
if(lastLocationRequest != null) {
lastLocationRequest.kill();
}
lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json").
queryParam("latlng", l.getLatitude() + "," + l.getLongitude()).
queryParam("key", GOOGLE_GEOCODING_KEY).
queryParam("language", "en").
queryParam("result_type", "street_address|point_of_interest").
getAsJsonMap(callbackMap -> {
Map data = callbackMap.getResponseData();
if(data != null) {
List results = (List)data.get("results");
if(results != null && results.size() > 0) {
Map firstResult = (Map)results.get(0);
name.onSucess((String)firstResult.get("formatted_address"));
}
}
});
}
SearchService
https://maps.googleapis.com/maps/api/place/autocomplete/json?
input=lev&location=32.072449,34.778613&radius=50000&key=API_KEY
Places Autocomplete
{
"predictions" : [
{
"description" : "Levinsky, Tel Aviv-Yafo, Israel",
"id" : "13fd8422602e10c4a7be775c88280b383a15f368",
"matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"structured_formatting" : {
"main_text" : "Levinsky",
"main_text_matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"secondary_text" : "Tel Aviv-Yafo, Israel"
},
"place_id" : "Eh9MZXZpbnNreSwgVGVsIEF2aXYtWWFmbywgSXNyYWVs",
"reference" : "-pQdrYHivUaFGV9GwZkfwp4xkjUL2Z2mpGNXJBv",
Places Autocomplete - Result
{
"predictions" : [
{
"description" : "Levinsky, Tel Aviv-Yafo, Israel",
"id" : "13fd8422602e10c4a7be775c88280b383a15f368",
"matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"structured_formatting" : {
"main_text" : "Levinsky",
"main_text_matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"secondary_text" : "Tel Aviv-Yafo, Israel"
},
"place_id" : "Eh9MZXZpbnNreSwgVGVsIEF2aXYtWWFmbywgSXNyYWVs",
"reference" : "-pQdrYHivUaFGV9GwZkfwp4xkjUL2Z2mpGNXJBv",
Places Autocomplete - Result
{
"predictions" : [
{
"description" : "Levinsky, Tel Aviv-Yafo, Israel",
"id" : "13fd8422602e10c4a7be775c88280b383a15f368",
"matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"structured_formatting" : {
"main_text" : "Levinsky",
"main_text_matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"secondary_text" : "Tel Aviv-Yafo, Israel"
},
"place_id" : "Eh9MZXZpbnNreSwgVGVsIEF2aXYtWWFmbywgSXNyYWVs",
"reference" : "-pQdrYHivUaFGV9GwZkfwp4xkjUL2Z2mpGNXJBv",
Places Autocomplete - Result
{
"predictions" : [
{
"description" : "Levinsky, Tel Aviv-Yafo, Israel",
"id" : "13fd8422602e10c4a7be775c88280b383a15f368",
"matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"structured_formatting" : {
"main_text" : "Levinsky",
"main_text_matched_substrings" : [
{
"length" : 3,
"offset" : 0
}
],
"secondary_text" : "Tel Aviv-Yafo, Israel"
},
"place_id" : "Eh9MZXZpbnNreSwgVGVsIEF2aXYtWWFmbywgSXNyYWVs",
"reference" : "-pQdrYHivUaFGV9GwZkfwp4xkjUL2Z2mpGNXJBv",
Places Autocomplete - Result
public static class SuggestionResult {
private final String mainText;
private final String secondaryText;
private final String fullText;
private final String placeId;
public SuggestionResult(String mainText, String secondaryText,
String fullText, String placeId) {
this.mainText = mainText;
this.secondaryText = secondaryText;
this.fullText = fullText;
this.placeId = placeId;
}
public String getPlaceId() {
return placeId;
}
public String getMainText() {
return mainText;
}
public String getSecondaryText() {
return secondaryText;
}
public String getFullText() {
return fullText;
}
SuggestionResult
public String getMainText() {
return mainText;
}
public String getSecondaryText() {
return secondaryText;
}
public String getFullText() {
return fullText;
}
public void getLocation(SuccessCallback<Location> result) {
Rest.get("https://maps.googleapis.com/maps/api/place/details/json").
queryParam("placeid", placeId).
queryParam("key", GOOGLE_PLACES_KEY).
getAsJsonMap(callbackMap -> {
Map r = (Map)callbackMap.getResponseData().get("result");
Map geomMap = (Map)r.get("geometry");
Map locationMap = (Map)geomMap.get("location");
double lat = Util.toDoubleValue(locationMap.get("lat"));
double lon = Util.toDoubleValue(locationMap.get("lng"));
result.onSucess(new Location(lat, lon));
});
}
}
SuggestionResult
private static ConnectionRequest lastSuggestionRequest;
private static String lastSuggestionValue;
private static final Map<String, List<SuggestionResult>>
locationCache = new HashMap<>();
SearchService

More Related Content

Similar to Creating an Uber Clone - Part XVII.pdf

Creating an Uber Clone - Part XV.pdf
Creating an Uber Clone - Part XV.pdfCreating an Uber Clone - Part XV.pdf
Creating an Uber Clone - Part XV.pdf
ShaiAlmog1
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Codemotion
 
How to Build Your Own Ride-Share App - codemotion amsterdam 2019
How to Build Your Own Ride-Share App - codemotion amsterdam 2019How to Build Your Own Ride-Share App - codemotion amsterdam 2019
How to Build Your Own Ride-Share App - codemotion amsterdam 2019
Richard Süselbeck
 
app.js.docx
app.js.docxapp.js.docx
app.js.docx
armitageclaire49
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
Christoffer Noring
 
Why Sifu?
Why Sifu?Why Sifu?
Why Sifu?
Sifu
 
Why Sifu
Why SifuWhy Sifu
Why Sifu
LambdaWorks
 
No internet? No Problem!
No internet? No Problem!No internet? No Problem!
No internet? No Problem!
Annyce Davis
 
097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión
GeneXus
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael HacksteinNoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael Hackstein
distributed matters
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Mark Needham
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
NoSQLmatters
 
NoSQL meets Microservices
NoSQL meets MicroservicesNoSQL meets Microservices
NoSQL meets Microservices
ArangoDB Database
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
Laurent_VB
 
Lekcja stylu
Lekcja styluLekcja stylu
Lekcja stylu
Wiktor Gworek
 
AngularJS Testing Strategies
AngularJS Testing StrategiesAngularJS Testing Strategies
AngularJS Testing Strategies
njpst8
 
GeoTechTalk InkSatogaeri Project
GeoTechTalk InkSatogaeri ProjectGeoTechTalk InkSatogaeri Project
GeoTechTalk InkSatogaeri Project
Kentaro Ishimaru
 
Kill the DBA
Kill the DBAKill the DBA
Kill the DBA
Knut Haugen
 
What's the deal with Android maps?
What's the deal with Android maps?What's the deal with Android maps?
What's the deal with Android maps?
Chuck Greb
 
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Stephan Schmidt
 

Similar to Creating an Uber Clone - Part XVII.pdf (20)

Creating an Uber Clone - Part XV.pdf
Creating an Uber Clone - Part XV.pdfCreating an Uber Clone - Part XV.pdf
Creating an Uber Clone - Part XV.pdf
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
How to Build Your Own Ride-Share App - codemotion amsterdam 2019
How to Build Your Own Ride-Share App - codemotion amsterdam 2019How to Build Your Own Ride-Share App - codemotion amsterdam 2019
How to Build Your Own Ride-Share App - codemotion amsterdam 2019
 
app.js.docx
app.js.docxapp.js.docx
app.js.docx
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
Why Sifu?
Why Sifu?Why Sifu?
Why Sifu?
 
Why Sifu
Why SifuWhy Sifu
Why Sifu
 
No internet? No Problem!
No internet? No Problem!No internet? No Problem!
No internet? No Problem!
 
097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael HacksteinNoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael Hackstein
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
 
NoSQL meets Microservices
NoSQL meets MicroservicesNoSQL meets Microservices
NoSQL meets Microservices
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
 
Lekcja stylu
Lekcja styluLekcja stylu
Lekcja stylu
 
AngularJS Testing Strategies
AngularJS Testing StrategiesAngularJS Testing Strategies
AngularJS Testing Strategies
 
GeoTechTalk InkSatogaeri Project
GeoTechTalk InkSatogaeri ProjectGeoTechTalk InkSatogaeri Project
GeoTechTalk InkSatogaeri Project
 
Kill the DBA
Kill the DBAKill the DBA
Kill the DBA
 
What's the deal with Android maps?
What's the deal with Android maps?What's the deal with Android maps?
What's the deal with Android maps?
 
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
ShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
ShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
maazsz111
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 

Recently uploaded (20)

zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 

Creating an Uber Clone - Part XVII.pdf

  • 1. Creating an Uber Clone - Part XVII
  • 2. WebServices from the Device? ✦I took a shortcut and chose to invoke the Google webservices from the device ✦The reason I did this is that I want to teach mobile programming not server programming ✦Google API keys would be more secure in the server ✦We can cache common queries in the server and reduce API costs ✦We can monitor the calls sent out and identify trends ✦We can instantly switch providers without shipping a new version of the app © Codename One 2017 all rights reserved
  • 3. Googles GIS Services ✦Geocoding ✦Reverse Geocoding ✦Directions ✦Places Autocomplete © Codename One 2017 all rights reserved
  • 4. public static final String GOOGLE_DIRECTIONS_KEY = "----"; public static final String GOOGLE_GEOCODING_KEY = "----"; public static final String GOOGLE_PLACES_KEY = "----"; New Fields in Globals
  • 6. { "results" : [ { "address_components" : [ { "long_name" : "277", "short_name" : "277", "types" : [ "street_number" ] }, { "long_name" : "Bedford Avenue", "short_name" : "Bedford Ave", "types" : [ "route" ] }, ... trimmed ... ], "formatted_address" : "277 Bedford Avenue, Brooklyn, NY 11211, USA", "geometry" : { "location" : { "lat" : 40.714232, "lng" : -73.9612889 Reverse Geocoding - Result
  • 7. { "results" : [ { "address_components" : [ { "long_name" : "277", "short_name" : "277", "types" : [ "street_number" ] }, { "long_name" : "Bedford Avenue", "short_name" : "Bedford Ave", "types" : [ "route" ] }, ... trimmed ... ], "formatted_address" : "277 Bedford Avenue, Brooklyn, NY 11211, USA", "geometry" : { "location" : { "lat" : 40.714232, "lng" : -73.9612889 Reverse Geocoding - Result
  • 8. public class SearchService { private static ConnectionRequest lastLocationRequest; public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) { if(l == null) { return; } if(lastLocationRequest != null) { lastLocationRequest.kill(); } lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json"). queryParam("latlng", l.getLatitude() + "," + l.getLongitude()). queryParam("key", GOOGLE_GEOCODING_KEY). queryParam("language", "en"). queryParam("result_type", "street_address|point_of_interest"). getAsJsonMap(callbackMap -> { Map data = callbackMap.getResponseData(); if(data != null) { List results = (List)data.get("results"); if(results != null && results.size() > 0) { Map firstResult = (Map)results.get(0); name.onSucess((String)firstResult.get("formatted_address")); } } }); } SearchService
  • 9. public class SearchService { private static ConnectionRequest lastLocationRequest; public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) { if(l == null) { return; } if(lastLocationRequest != null) { lastLocationRequest.kill(); } lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json"). queryParam("latlng", l.getLatitude() + "," + l.getLongitude()). queryParam("key", GOOGLE_GEOCODING_KEY). queryParam("language", "en"). queryParam("result_type", "street_address|point_of_interest"). getAsJsonMap(callbackMap -> { Map data = callbackMap.getResponseData(); if(data != null) { List results = (List)data.get("results"); if(results != null && results.size() > 0) { Map firstResult = (Map)results.get(0); name.onSucess((String)firstResult.get("formatted_address")); } } }); } SearchService
  • 10. public class SearchService { private static ConnectionRequest lastLocationRequest; public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) { if(l == null) { return; } if(lastLocationRequest != null) { lastLocationRequest.kill(); } lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json"). queryParam("latlng", l.getLatitude() + "," + l.getLongitude()). queryParam("key", GOOGLE_GEOCODING_KEY). queryParam("language", "en"). queryParam("result_type", "street_address|point_of_interest"). getAsJsonMap(callbackMap -> { Map data = callbackMap.getResponseData(); if(data != null) { List results = (List)data.get("results"); if(results != null && results.size() > 0) { Map firstResult = (Map)results.get(0); name.onSucess((String)firstResult.get("formatted_address")); } } }); } SearchService
  • 11. public class SearchService { private static ConnectionRequest lastLocationRequest; public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) { if(l == null) { return; } if(lastLocationRequest != null) { lastLocationRequest.kill(); } lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json"). queryParam("latlng", l.getLatitude() + "," + l.getLongitude()). queryParam("key", GOOGLE_GEOCODING_KEY). queryParam("language", "en"). queryParam("result_type", "street_address|point_of_interest"). getAsJsonMap(callbackMap -> { Map data = callbackMap.getResponseData(); if(data != null) { List results = (List)data.get("results"); if(results != null && results.size() > 0) { Map firstResult = (Map)results.get(0); name.onSucess((String)firstResult.get("formatted_address")); } } }); } SearchService
  • 12. public class SearchService { private static ConnectionRequest lastLocationRequest; public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) { if(l == null) { return; } if(lastLocationRequest != null) { lastLocationRequest.kill(); } lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json"). queryParam("latlng", l.getLatitude() + "," + l.getLongitude()). queryParam("key", GOOGLE_GEOCODING_KEY). queryParam("language", "en"). queryParam("result_type", "street_address|point_of_interest"). getAsJsonMap(callbackMap -> { Map data = callbackMap.getResponseData(); if(data != null) { List results = (List)data.get("results"); if(results != null && results.size() > 0) { Map firstResult = (Map)results.get(0); name.onSucess((String)firstResult.get("formatted_address")); } } }); } SearchService
  • 13. public class SearchService { private static ConnectionRequest lastLocationRequest; public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) { if(l == null) { return; } if(lastLocationRequest != null) { lastLocationRequest.kill(); } lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json"). queryParam("latlng", l.getLatitude() + "," + l.getLongitude()). queryParam("key", GOOGLE_GEOCODING_KEY). queryParam("language", "en"). queryParam("result_type", "street_address|point_of_interest"). getAsJsonMap(callbackMap -> { Map data = callbackMap.getResponseData(); if(data != null) { List results = (List)data.get("results"); if(results != null && results.size() > 0) { Map firstResult = (Map)results.get(0); name.onSucess((String)firstResult.get("formatted_address")); } } }); } SearchService
  • 14. public class SearchService { private static ConnectionRequest lastLocationRequest; public static void nameMyCurrentLocation(Location l, SuccessCallback<String> name) { if(l == null) { return; } if(lastLocationRequest != null) { lastLocationRequest.kill(); } lastLocationRequest = Rest.get("https://maps.googleapis.com/maps/api/geocode/json"). queryParam("latlng", l.getLatitude() + "," + l.getLongitude()). queryParam("key", GOOGLE_GEOCODING_KEY). queryParam("language", "en"). queryParam("result_type", "street_address|point_of_interest"). getAsJsonMap(callbackMap -> { Map data = callbackMap.getResponseData(); if(data != null) { List results = (List)data.get("results"); if(results != null && results.size() > 0) { Map firstResult = (Map)results.get(0); name.onSucess((String)firstResult.get("formatted_address")); } } }); } SearchService
  • 16. { "predictions" : [ { "description" : "Levinsky, Tel Aviv-Yafo, Israel", "id" : "13fd8422602e10c4a7be775c88280b383a15f368", "matched_substrings" : [ { "length" : 3, "offset" : 0 } ], "structured_formatting" : { "main_text" : "Levinsky", "main_text_matched_substrings" : [ { "length" : 3, "offset" : 0 } ], "secondary_text" : "Tel Aviv-Yafo, Israel" }, "place_id" : "Eh9MZXZpbnNreSwgVGVsIEF2aXYtWWFmbywgSXNyYWVs", "reference" : "-pQdrYHivUaFGV9GwZkfwp4xkjUL2Z2mpGNXJBv", Places Autocomplete - Result
  • 17. { "predictions" : [ { "description" : "Levinsky, Tel Aviv-Yafo, Israel", "id" : "13fd8422602e10c4a7be775c88280b383a15f368", "matched_substrings" : [ { "length" : 3, "offset" : 0 } ], "structured_formatting" : { "main_text" : "Levinsky", "main_text_matched_substrings" : [ { "length" : 3, "offset" : 0 } ], "secondary_text" : "Tel Aviv-Yafo, Israel" }, "place_id" : "Eh9MZXZpbnNreSwgVGVsIEF2aXYtWWFmbywgSXNyYWVs", "reference" : "-pQdrYHivUaFGV9GwZkfwp4xkjUL2Z2mpGNXJBv", Places Autocomplete - Result
  • 18. { "predictions" : [ { "description" : "Levinsky, Tel Aviv-Yafo, Israel", "id" : "13fd8422602e10c4a7be775c88280b383a15f368", "matched_substrings" : [ { "length" : 3, "offset" : 0 } ], "structured_formatting" : { "main_text" : "Levinsky", "main_text_matched_substrings" : [ { "length" : 3, "offset" : 0 } ], "secondary_text" : "Tel Aviv-Yafo, Israel" }, "place_id" : "Eh9MZXZpbnNreSwgVGVsIEF2aXYtWWFmbywgSXNyYWVs", "reference" : "-pQdrYHivUaFGV9GwZkfwp4xkjUL2Z2mpGNXJBv", Places Autocomplete - Result
  • 19. { "predictions" : [ { "description" : "Levinsky, Tel Aviv-Yafo, Israel", "id" : "13fd8422602e10c4a7be775c88280b383a15f368", "matched_substrings" : [ { "length" : 3, "offset" : 0 } ], "structured_formatting" : { "main_text" : "Levinsky", "main_text_matched_substrings" : [ { "length" : 3, "offset" : 0 } ], "secondary_text" : "Tel Aviv-Yafo, Israel" }, "place_id" : "Eh9MZXZpbnNreSwgVGVsIEF2aXYtWWFmbywgSXNyYWVs", "reference" : "-pQdrYHivUaFGV9GwZkfwp4xkjUL2Z2mpGNXJBv", Places Autocomplete - Result
  • 20. public static class SuggestionResult { private final String mainText; private final String secondaryText; private final String fullText; private final String placeId; public SuggestionResult(String mainText, String secondaryText, String fullText, String placeId) { this.mainText = mainText; this.secondaryText = secondaryText; this.fullText = fullText; this.placeId = placeId; } public String getPlaceId() { return placeId; } public String getMainText() { return mainText; } public String getSecondaryText() { return secondaryText; } public String getFullText() { return fullText; } SuggestionResult
  • 21. public String getMainText() { return mainText; } public String getSecondaryText() { return secondaryText; } public String getFullText() { return fullText; } public void getLocation(SuccessCallback<Location> result) { Rest.get("https://maps.googleapis.com/maps/api/place/details/json"). queryParam("placeid", placeId). queryParam("key", GOOGLE_PLACES_KEY). getAsJsonMap(callbackMap -> { Map r = (Map)callbackMap.getResponseData().get("result"); Map geomMap = (Map)r.get("geometry"); Map locationMap = (Map)geomMap.get("location"); double lat = Util.toDoubleValue(locationMap.get("lat")); double lon = Util.toDoubleValue(locationMap.get("lng")); result.onSucess(new Location(lat, lon)); }); } } SuggestionResult
  • 22. private static ConnectionRequest lastSuggestionRequest; private static String lastSuggestionValue; private static final Map<String, List<SuggestionResult>> locationCache = new HashMap<>(); SearchService