You need to sign in to do that
Don't have an account?

latitude longitude trigger
Currently I am captuign a users location via script within a visualforce page.
This is fine but makes I cannot reuse the logic. Would it be a better option to use in in a Apex Class so that the location capturing process can be used on any Object? If so, how can I make the Class univeral to any object?
Thanks
<script> window.onload = function() { var startPos; var geoSuccess = function(position) { startPos = position; document.getElementById('{!$Component.inpform.pb.pbs.startLat}').value=startPos.coords.latitude; document.getElementById('{!$Component.inpform.pb.pbs.startLon}').value=startPos.coords.longitude; //alert('@@@ ' + document.getElementsByClassName('findclass')[0].value); document.getElementsByClassName('Latclass')[0].value =startPos.coords.latitude; document.getElementsByClassName('Lonclass')[0].value =startPos.coords.longitude; }; navigator.geolocation.getCurrentPosition(geoSuccess); }; </script>
This is fine but makes I cannot reuse the logic. Would it be a better option to use in in a Apex Class so that the location capturing process can be used on any Object? If so, how can I make the Class univeral to any object?
Thanks
Hope you are good!
I have created an LWC component just to do this thing. This component is a reusable component and can be used anywhere. If given the record context through RecordPage on lightning app builder, this can also set geolocation fields on any record.
This is the link: https://www.playg.app/play/lwc-to-set-geolocation-to-any-object
Please have a look at it and let me know if you have any more questions.
Thanks
All Answers
Hope you are good!
I have created an LWC component just to do this thing. This component is a reusable component and can be used anywhere. If given the record context through RecordPage on lightning app builder, this can also set geolocation fields on any record.
This is the link: https://www.playg.app/play/lwc-to-set-geolocation-to-any-object
Please have a look at it and let me know if you have any more questions.
Thanks
That looks very promising. So can I call the LWC from a Visualforce Page Controller?
Thank you for your help.
M
Yes, you can use LWC on visualforce page. You can do that by going through this link: https://releasenotes.docs.salesforce.com/en-us/summer19/release-notes/rn_lwc_vf.htm
Thanks
M