【发布时间】:2011-04-16 00:49:40
【问题描述】:
我正在尝试在一个网站上实现一个简单的脚本,该脚本将从 google 的 ajax API 返回 base64 编码信息。这是我目前正在玩的:
<html>
<head>
<script src="http://www.google.com/jsapi?key=ABQIAAAA0duujonFsEX871htGWZBHRS76H0qhS7Lb-D1Gd0Mnaiuid8Z7BQIyz2kMpojKizoyiCQA4yRkKAKug" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
var location = 'Unable to determine your location.';
if (google.loader.ClientLocation) {
var loc = google.loader.ClientLocation;
location = 'Country: <strong>' + loc.address.country + '</strong>, Region: <strong>' + loc.address.region + '</strong>, City: <strong>' +
loc.address.city + '</strong>, Lat/Long: <strong>' + loc.latitude + ', ' + loc.longitude + '</strong>';
}
jQuery('.geolocation').html(location);
});
</script>
</head>
<body>
<span class="geolocation"></span>
</body>
</html>
它返回我试图正确获取的信息,但我需要对单独的部分进行 base64 编码,例如国家、地区、城市、纬度和经度。在 php 中它会很简单,但我无法弄清楚如何在 javascript 中做到这一点。任何帮助将不胜感激。
【问题讨论】:
标签: javascript geolocation base64