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

PDF
Creating an Uber Clone - Part XXIX.pdf
ShaiAlmog1
 
PDF
Creating an Uber Clone - Part XVII - Transcript.pdf
ShaiAlmog1
 
PDF
Creating an Uber Clone - Part XVIII - Transcript.pdf
ShaiAlmog1
 
PDF
Creating an Uber Clone - Part XXIX - Transcript.pdf
ShaiAlmog1
 
PDF
10. Kapusta, Stofanak - eGlu
MobCon
 
PDF
Developing Apps for Emerging Markets
Annyce Davis
 
PDF
Migrating from Flux to Redux. Why and how.
Astrails
 
PDF
Functional programming using underscorejs
偉格 高
 
Creating an Uber Clone - Part XXIX.pdf
ShaiAlmog1
 
Creating an Uber Clone - Part XVII - Transcript.pdf
ShaiAlmog1
 
Creating an Uber Clone - Part XVIII - Transcript.pdf
ShaiAlmog1
 
Creating an Uber Clone - Part XXIX - Transcript.pdf
ShaiAlmog1
 
10. Kapusta, Stofanak - eGlu
MobCon
 
Developing Apps for Emerging Markets
Annyce Davis
 
Migrating from Flux to Redux. Why and how.
Astrails
 
Functional programming using underscorejs
偉格 高
 

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

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

More from ShaiAlmog1 (20)

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

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
The Future of Artificial Intelligence (AI)
Mukul
 

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