You need to sign in to do that
Don't have an account?
sawaji varun
How to display address on the basis of latitude and Longitude
I'm able to track current location latitude and Longitude. I want to display the address on the basis of latitude and Longitude. How to achieve it. The code is given below. I have created the one geolocation field and address as text field.
LocatorPage.vfp
<apex:page StandardController="Task" showHeader="true" sidebar="false" extensions="visitController">
<script>
var pos = {};
function success(position) {
pos = position.coords;
console.log(pos);
}
function error(msg) {
console.log(msg);
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
function setPos() {
var inputs = document.getElementsByTagName('input');
for(var x = 0; x < inputs.length; x++) {
if(inputs[x].id.indexOf('contactlat') >= 0) { inputs[x].value = pos.latitude; }
if(inputs[x].id.indexOf('contactlong') >= 0) { inputs[x].value = pos.longitude; }
if(inputs[x].id.indexOf('contactaddress') >= 0) { inputs[x].value = address; }
}
}
visitController.apxp
public class visitController {
public Task tsk{
get {
if (tsk == null)
tsk = new Task();
return tsk;
}
set;
}
public Opportunity opp {get;set;}
public visitController(ApexPages.StandardController controller) {
this.tsk = (Task)Controller.getRecord();
tsk.Id = System.currentPageReference().getParameters().get('Id');
}
public PageReference save() {
//tsk.WhatId = opp.Id;
insert tsk;
pageReference pageref= new pageReference('/' + tsk.Id);
Task tsk = new Task();
return pageref;
}
}
LocatorPage.vfp
<apex:page StandardController="Task" showHeader="true" sidebar="false" extensions="visitController">
<script>
var pos = {};
function success(position) {
pos = position.coords;
console.log(pos);
}
function error(msg) {
console.log(msg);
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
function setPos() {
var inputs = document.getElementsByTagName('input');
for(var x = 0; x < inputs.length; x++) {
if(inputs[x].id.indexOf('contactlat') >= 0) { inputs[x].value = pos.latitude; }
if(inputs[x].id.indexOf('contactlong') >= 0) { inputs[x].value = pos.longitude; }
if(inputs[x].id.indexOf('contactaddress') >= 0) { inputs[x].value = address; }
}
}
visitController.apxp
public class visitController {
public Task tsk{
get {
if (tsk == null)
tsk = new Task();
return tsk;
}
set;
}
public Opportunity opp {get;set;}
public visitController(ApexPages.StandardController controller) {
this.tsk = (Task)Controller.getRecord();
tsk.Id = System.currentPageReference().getParameters().get('Id');
}
public PageReference save() {
//tsk.WhatId = opp.Id;
insert tsk;
pageReference pageref= new pageReference('/' + tsk.Id);
Task tsk = new Task();
return pageref;
}
}