You need to sign in to do that
Don't have an account?
Milan Hrdlicka
getting latitude and logtitude data
I have two classes below used for retrieving data using a web call out - this worked when I ran below code in the developer console:
getGPS gps = new getGPS();
gps.getLng();
gps.getLat();
In Log I got longtitude and latitude whci is NOT HAPPENNING NOW FOR SOME REASON.
Can anyone shed a bit of light into this as this is giving me a headache, this ceased to work and I dont know why.
Appreciate your help, Milan
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
getGPS gps = new getGPS();
gps.getLng();
gps.getLat();
In Log I got longtitude and latitude whci is NOT HAPPENNING NOW FOR SOME REASON.
Can anyone shed a bit of light into this as this is giving me a headache, this ceased to work and I dont know why.
Appreciate your help, Milan
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class getGPS {
String endPointString = 'http://maps.googleapis.com/maps/api/geocode/json?address='Šafaříkova 785/1, 120 00 Praha, Vinohrady';
double lng;
double lat;
public double getLng() {
return lng;
}
public double getLat() {
return lat;
}
public void getGPSdata() {
Http httpProtocol = new Http();
HttpRequest request = new HttpRequest();
String endpoint = endPointString;
request.setEndPoint(endpoint);
request.setMethod('GET');
HttpResponse response = httpProtocol.send(request);
String jsonString = response.getBody();
googleAddress addr = googleAddress.parse(jsonString);
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
this.lng=lng;
this.lat=lat;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class googleAddress {
public class Address_components {
public String long_name;
public String short_name;
public List<String> types;
}
public class Geometry {
public Location location;
public String location_type;
public Viewport viewport;
}
public List<Results> results;
public String status;
public Location firstLoc;
public class Results {
public List<Address_components> address_components;
public String formatted_address;
public Geometry geometry;
public Boolean partial_match;
public String place_id;
public List<String> types;
}
public class Viewport {
public Location northeast;
public Location southwest;
}
public class Location {
public Double lat;
public Double lng;
}
public static googleAddress parse(String json) {
googleAddress returnAddr;
returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
if (!returnAddr.results.isEmpty()){
returnAddr.firstLoc = returnAddr.results[0].geometry.location;
}
return returnAddr;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
String endPointString = 'http://maps.googleapis.com/maps/api/geocode/json?address='Šafaříkova 785/1, 120 00 Praha, Vinohrady';
double lng;
double lat;
public double getLng() {
return lng;
}
public double getLat() {
return lat;
}
public void getGPSdata() {
Http httpProtocol = new Http();
HttpRequest request = new HttpRequest();
String endpoint = endPointString;
request.setEndPoint(endpoint);
request.setMethod('GET');
HttpResponse response = httpProtocol.send(request);
String jsonString = response.getBody();
googleAddress addr = googleAddress.parse(jsonString);
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
this.lng=lng;
this.lat=lat;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class googleAddress {
public class Address_components {
public String long_name;
public String short_name;
public List<String> types;
}
public class Geometry {
public Location location;
public String location_type;
public Viewport viewport;
}
public List<Results> results;
public String status;
public Location firstLoc;
public class Results {
public List<Address_components> address_components;
public String formatted_address;
public Geometry geometry;
public Boolean partial_match;
public String place_id;
public List<String> types;
}
public class Viewport {
public Location northeast;
public Location southwest;
}
public class Location {
public Double lat;
public Double lng;
}
public static googleAddress parse(String json) {
googleAddress returnAddr;
returnAddr = (googleAddress) System.JSON.deserialize(json, googleAddress.class);
if (!returnAddr.results.isEmpty()){
returnAddr.firstLoc = returnAddr.results[0].geometry.location;
}
return returnAddr;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have also implementated the MAP API.
Which is working well in my scenario. which update record on Account.
Please find below code:
Thanks
Ajay Mishra
Email: mishraajay.m1@gmail.com
So should I replace my "googleAddress" class with this code?
This is giving me so much confusion :)
Sorry to be bothersome.
Milan