SimpleGeo Javascript SDK 帮助
我是 Javascript 新手,我正在尝试最终制作一些东西,通过使用 HTML5 的 getLocation API 来获取用户位置,并使用 simpleGeo 来获取坐标的构建。
到目前为止,我正在尝试让 SimpleGeo 工作,并且我有这个:
var client = new simplegeo.ContextClient('YUpXKUcaTr2ZE5T5vkhaDRAXWbDbaZts');
function displayData(err, data) {
if (err) {
console.error(err);
} else {
console.log(JSON.stringify(data));
}
}
client.getLocation({enableHighAccuracy: true}, function(err, position) {
if (err) {
// Could not retrieve location information. Check err for more information
} else {
// Latitude and longitude available in position.coords
var lat = position.coords.latitude;
var lon = position.coords.longitude;
$('#header').html('<p>your latitude is: ' + lat + '. And your longitude is: ' + lon + '.</p>');
}
});
client.getNearbyAddress(37.765850, -122.437094), function(err, position) {
if (err) {
$('#header').html('<p>Sorry we couldn't locate an address.</p>)
} else {
$('#header').html('<p>Your Street number is ' + street_number + '</p>');
}
});
然而,这表示 Chrome 中的 JS 控制台中出现意外的标识符。任何帮助将不胜感激。 :)
I'm new to Javascript and I'm trying to eventually make something that will get the users location in using the getLocation API with HTML5, and use simpleGeo to get the building of the coordinates.
So far I'm trying to get SimpleGeo working and I have this:
var client = new simplegeo.ContextClient('YUpXKUcaTr2ZE5T5vkhaDRAXWbDbaZts');
function displayData(err, data) {
if (err) {
console.error(err);
} else {
console.log(JSON.stringify(data));
}
}
client.getLocation({enableHighAccuracy: true}, function(err, position) {
if (err) {
// Could not retrieve location information. Check err for more information
} else {
// Latitude and longitude available in position.coords
var lat = position.coords.latitude;
var lon = position.coords.longitude;
$('#header').html('<p>your latitude is: ' + lat + '. And your longitude is: ' + lon + '.</p>');
}
});
client.getNearbyAddress(37.765850, -122.437094), function(err, position) {
if (err) {
$('#header').html('<p>Sorry we couldn't locate an address.</p>)
} else {
$('#header').html('<p>Your Street number is ' + street_number + '</p>');
}
});
However this says unexpected identifier in the JS console in Chrome. Any help would be appreciated. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我实际上是开发者倡导者@SimpleGeo。您的函数 displayData 看起来没有执行任何操作。 var street_number 也未定义。您想获取用户的地址吗?
这是返回用户邻居的示例:
I am actually the Developer Advocate @ SimpleGeo. Your function displayData doesn't look like it is doing anything. Also var street_number isn't defined. Are you looking to get the user's address?
Here is an example that returns the user's neighborhood: