Capture Latitude, Longitude using JS on Leads editview

I have added Latitude and Longitude fields in my Leads module. The way it should work is - whenever the editview is opened, the latitude and longitude fields should get populated automatically through Javascript functions.

I have done the following but it doesn’t seem to work -

  1. added the following to custom/modules/Leads/metadata/editviewdefs.php
'includes'=> array(
    array('file'=>'custom/modules/Leads/latlong.js'),
),
  1. Created a js file named latlong.js in ‘custom/modules/Leads/’ and put the following code there -
function initGeolocation(){
    if( navigator.geolocation ){
        // Call getCurrentPosition with success and failure callbacks
        navigator.geolocation.getCurrentPosition( success, fail );
    }
    else{
        alert("Sorry, your browser does not support geolocation services.");
    }
}

function success(position){
    document.getElementById('jjwg_maps_lng_c').value = position.coords.longitude;
    document.getElementById('jjwg_maps_lat_c').value = position.coords.latitude;
}

function fail(){
    // Could not obtain location
}
  1. Did Quick Repair and Rebuild and opened the edit view for Leads module.

But it doesn’t work. The latitude and longitude fields are still populated with a default value of 0.00000000

Can anyone tell me what am I doing wrong? I have just started working on SuiteCRM. So would need a little helping hand here.

Thanks.

I figured it out. I had forgotten to bind the ‘initGeolocation’ function to an event. After binding it to ‘onload’ event, it is working fine.

Hi I would like some help with the Latitude and Longitude. Would it be possible for you to help me?

Thanks

Fazleh

Sure. Let me know how I can help.

Thanks. I wanted to have longitude and Latitude take precedence over the ZIP code. This is so that I can have a map with all the leads and accounts on a single map. Here in Zambia we do not yet use zip codes. Another problem (which is the main one) is that I do not have php knowledge but I really love SuiteCRM. :wink:

Hi, I used this code for my custom module called Geo , but it is not working.
When I checked, alert is coming in this condition ,
if( navigator.geolocation ){
alert(“Success”)
// Call getCurrentPosition with success and failure callbacks
navigator.geolocation.getCurrentPosition( success, fail );
}

but it is not coming to this function

function success(position){

//document.getElementById('longitude').value = position.coords.longitude;
//document.getElementById('latitude').value = position.coords.latitude;

document.getElementById(‘longitude’).value = “77.1025”;
document.getElementById(‘latitude’).value = “28.7041”;
}

What will be error?

This is the code what I have used,

$(document).ready(function(){
initGeolocation();
});

function initGeolocation(){

if( navigator.geolocation ){

alert(“success”)
// Call getCurrentPosition with success and failure callbacks
navigator.geolocation.getCurrentPosition( success, fail );
}
else{
alert(“Sorry, your browser does not support geolocation services.”);
}
}

function success(position){

//document.getElementById('longitude').value = position.coords.longitude;
//document.getElementById('latitude').value = position.coords.latitude;

document.getElementById(‘longitude’).value = “77.1025”;
document.getElementById(‘latitude’).value = “28.7041”;
}

function fail(){
// Could not obtain location
}

How to get geolocation in SuiteCRM?

Hello, I am having a similar problem, (I am new in this world of SUITE ), in the editview when I fill in the fields, thanks to googleAddressAutocomplete, the fields latitude and logitude are correctly filled BUT when I pass to the detailview, the latitude and longitude fields both contain the value 1,000.00000000, what could be the problem? Can you help me? I’m very inexperienced.