2011-07-13 83 views
1

你好我使用以下GeoLocation中的功能正如你看到它在字段中的值寫入到讓訪客瀏覽HTML5的jQuery GeoLocation中與谷歌地圖

function success(position) { 
    var s = document.querySelector('#location'); 

    if (s.className == 'success') { 
    return; 
    } 

    s.value = "found you!"; 
    s.className = 'success'; 

    var mapcanvas = document.createElement('div'); 
    mapcanvas.id = 'mapcanvas'; 
    mapcanvas.style.height = '200px'; 
    mapcanvas.style.width = '380px'; 

    document.querySelector('article').appendChild(mapcanvas); 

    var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
    var myOptions = { 
    zoom: 15, 
    center: latlng, 
    mapTypeControl: false, 
    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions); 

    var marker = new google.maps.Marker({ 
     position: latlng, 
     map: map, 
     title:"You are here!" 
    }); 
} 

function error(msg) { 
    var s = document.querySelector('#status'); 
    s.innerHTML = typeof msg == 'string' ? msg : "failed"; 
    s.className = 'fail'; 

    // console.log(arguments); 
} 

if (navigator.geolocation) { 
    navigator.geolocation.getCurrentPosition(success, error); 
} else { 
    error('not supported'); 
} 

的位置「找到你了!」當過程成功時。

現在我需要而不是寫「找到你!」我需要寫下訪客的位置。

因此,如果成員是在羅馬,它會寫「羅馬,意大利」

如何實現的呢?

感謝您的幫助!

回答

1

您想要進行地理編碼(或反向地理編碼)。我在我的支持論壇上寫了一個簡短的概述here。查看帖子末尾的鏈接。

更多涉及的示例:我的tutorial使用谷歌地圖,jquery,標記和地理編碼,包括從lat/lng coords獲取完整地址的源代碼。

+0

mmhh?更直接的東西? –