可以使用 W3C 地理位置 API 检索用户浏览器的地理位置。它非常深入,所以如果你不喜欢阅读,我已经包含了一些我正在使用的原型代码。它应该显示一个带有您当前浏览器位置的标记。
http://dev.w3.org/geo/api/spec-source.html
您可以将经度和纬度信息存储到数据库中,然后对其进行解析并将标记插入到带有 javascript 的谷歌地图中。
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
function initialize(location) {
var latlng = new google.maps.LatLng(location.coords.latitude,location.coords.longitude);
var myOptions = {
zoom: 19,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"Hello World!"
});
}
</script>
</head>
<body onload="navigator.geolocation.getCurrentPosition(initialize);">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>