【发布时间】:2012-09-13 14:50:20
【问题描述】:
我正在使用地理定位创建一个网络应用程序。到目前为止,我已经设置并运行了它,因此当用户访问时会提示他们允许位置服务,然后会显示一个警报(不是永久性的,仅用于测试目的。)
我正在使用这个:
navigator.geolocation.getCurrentPosition(foundLocation, noLocation, {enableHighAccuracy:true});
function foundLocation(position)
{
var lat = position.coords.latitude;
var long = position.coords.longitude;
alert('We know you are here '+ lat +','+ long);
}
function noLocation()
{
alert('Could not find location');
}
然后我在此之外有一个名为“地址”的变量,它是 API 调用的 URL:
address = "http://api.wunderground.com/api/geolookup/hourly/conditions/astronomy/alerts/forecast/q/[LOCATION].json"
我的问题是如何将lat 和long 从函数中取出并将它们插入到URL 中?我尝试了一些方法,但它们都返回“未定义”,所以我显然做错了。
非常感谢任何帮助!
谢谢。
【问题讨论】:
标签: jquery api function web-applications geolocation