打印Javascript时出现问题
我不是Javascript的高手,我似乎被卡住了 我有一张地图,我需要一个位置的Lat/Long(这很好),但是输出在一个警报框中。我只需要价值观本身 例如文件编写(latt);文件编写(long) 目前,这是输出框的代码:打印Javascript时出现问题,javascript,Javascript,我不是Javascript的高手,我似乎被卡住了 我有一张地图,我需要一个位置的Lat/Long(这很好),但是输出在一个警报框中。我只需要价值观本身 例如文件编写(latt);文件编写(long) 目前,这是输出框的代码: function showPointLatLng(point) { alert("Latitude: " + point.lat() + "\nLongitude: " + point.lng()); } 任何帮助都会很好,谢谢 p.S 我想这是控制器: func
function showPointLatLng(point)
{
alert("Latitude: " + point.lat() + "\nLongitude: " + point.lng());
}
任何帮助都会很好,谢谢
p.S
我想这是控制器:
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");
}
看起来您可以将
showPointLatLng
调用与以下内容交换:
document.write( point.lat() + "," + point.lng() );
由于lat/long来自对现有
点
对象的方法的调用。而不是文档。编写
您可以执行以下操作:
var info = document.createElement('div');
info.innerHTML = point.lat() + "," + point.lng();
document.body.appendChild(info);
如果你问的是如何让它工作
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!*/ }
});
您必须将此代码包装在ShowPointLatling函数obv中。。您的“point”参数是否已定义?我不知道它是否已定义在函数中编写以下代码:“console.log(point)”并查看控制台(firebug | chrome或safari dev toolbar |或IE webtoolbar),您应该有一个类似“undefined”或特定对象的输出