You need to sign in to do that
Don't have an account?
Milan Hrdlicka
Data to be filled automatically once other details are entered
Hello,
I have a custom object "Shop__c". When I enter address details to appropriate fields, once these are entered I need t latitude and longtitude details (geolocation) to be filled automatically.
Longtitude and Latitude data are placed in a variable in separate class.
Can anyone advise what would be the best to achieve this?
Appreciate your help,
Milan
I have a custom object "Shop__c". When I enter address details to appropriate fields, once these are entered I need t latitude and longtitude details (geolocation) to be filled automatically.
Longtitude and Latitude data are placed in a variable in separate class.
Can anyone advise what would be the best to achieve this?
Appreciate your help,
Milan
What do you use for getting the latitude/longitude values from an address?
Close solution: https://developer.salesforce.com/forums/?id=906F00000009EKmIAM
Alain
class1:
-----------
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;
}
}
class2:
-----------
public class JSONpokus1 {
@future(callout=true)
public static void parseJSONResponse() {
Http httpProtocol = new Http();
HttpRequest request = new HttpRequest();
String endpoint = 'http://maps.googleapis.com/maps/api/geocode/json?address=Nuselská 23, 140 00, Praha 4';
request.setEndPoint(endpoint);
request.setMethod('GET');
HttpResponse response = httpProtocol.send(request);
String jsonString = response.getBody();
System.debug(jsonString);
googleAddress addr = googleAddress.parse(jsonString);
googleAddress.Location loc = addr.firstLoc;
double lng = loc.lng;
double lat = loc.lat;
system.debug(lng);
system.debug(lat);
}
}
https://developer.salesforce.com/blogs/developer-relations/2015/02/apex-continuations-asynchronous-callouts-visualforce-pages.html
But it is not necessary if you use a Visualforce page and an Apex controller.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_mobile_example.htm
<apex:page controller="mapController" showHeader="false">
Alain