我試圖使用google.loader.ClientLocation以及地圖API來獲取訪問者的位置並在其上居中放置地圖。以下對我來說很好(在Safari,Firefox和Chrome上),但我需要測試它的一個朋友(在Safari和Firefox中)只看到一個帶有Google徽標的白色框。獲取用戶位置,google.loader.ClientLocation爲我工作但不是其他人
<script type="text/javascript" src="http://www.google.com/jsapi?key=MykeyHere"></script>
<script type="text/javascript">
google.load("maps", "2");
</script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("local_map"));
map.setMapType(G_PHYSICAL_MAP);
map.setCenter(new GLatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude), 15);
// map.setCenter(new GLatLng(54.5975, -5.920278), 15);
map.setUIToDefault();
}
</script>
任何想法可能會出錯?該網站位於http://www.chris-armstrong.com/ticktalk(地圖接近底部)
謝謝,基本上它不是一門精確的科學。 IP地址是獲取沒有GPS功能的位置的唯一途徑嗎? –
@Chris,確切地說,它不是確切的。您可以使用Javascript W3C Geolocation API從瀏覽器(可能使用GPS或WiFi三角測量或其他方法,取決於瀏覽器和計算機)獲取更精確的位置。我已經添加了一些鏈接到我的答案,以提供更多的上下文。 – npdoty
我得到'其實,我不能以這種方式猜測你的位置。'當訪問您的測試頁面時。 –