0

I'm not the best with Javascript and I seem to have got stuck.

I have a map in place and I need the Lat/Long for a location (that's fine) but the output comes in an alert box. I just need the values themselves.

E.g document.write(latt); document.write(longg);

At the moment this is the code that outputs the box:

function showPointLatLng(point)
{
    alert("Latitude: " + point.lat() + "\nLongitude: " + point.lng());
}

Any help would be great, Thanks!

P.S

I think this is the controller:

function usePointFromPostcode(postcode, callbackFunction) {

    localSearch.setSearchCompleteCallback(null, 
        function() {

            if (localSearch.results[0])
            {       
                var resultLat = localSearch.results[0].lat;
                var resultLng = localSearch.results[0].lng;
                var point = new GLatLng(resultLat,resultLng);
                callbackFunction(point);
            }else{
                alert("Postcode not found!");
            }
        }); 

    localSearch.execute(postcode + ", UK");
}

3 Answers 3

1

Looks like you can swap the showPointLatLng call with:

document.write( point.lat() + "," + point.lng() ); 

As lat/long come from calls to methods of the existing point object.

Sign up to request clarification or add additional context in comments.

Comments

1

If you are asking how to make that work...

function showPointLatLng(point) {
    document.write("Latitude: " + point.lat() + "\nLongitude: " + point.lng());
}
// Eg, ...
showPointLatLng({
    lat : function(){ return 98; }
    lng : function(){ return 42; /*the meaning of life!*/ }
});

Comments

0

Instead of document.write you could do something like this:

var info = document.createElement('div');
info.innerHTML = point.lat() + "," + point.lng();

document.body.appendChild(info);

3 Comments

you have to wrap this code within your showPointLatLng function obv.. is your 'point' parameter defined?
I have no idea if it's defined
inside the function write this code : 'console.log(point)' and look at the console (firebug | chrome or safari dev toolbar | or IE webtoolbar), you should have an output like 'undefined' or a particular object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.