我目前正在使用Google API指出谷歌地图上的位置。
这是google-maps-utility-library-v3
链接
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html
我写了这段代码
<script type="text/javascript">
function initialize() {
var secheltLoc = new google.maps.LatLng(49.47216, -123.76307);
var myMapOptions = {
zoom: 15
,center: secheltLoc
,mapTypeId: google.maps.MapTypeId.ROADMAP
};
var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
var marker = new google.maps.Marker({
map: theMap,
draggable: true,
position: new google.maps.LatLng(49.47216, -123.76307),
visible: true
});
}
function getLatLong(){
var secheltLoc = new google.maps.LatLng(49.47216, -123.76307);
var myMapOptions = {
zoom: 15
,center: secheltLoc
,mapTypeId: google.maps.MapTypeId.ROADMAP
};
var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
var marker = new google.maps.Marker({
map: theMap,
draggable: true,
position: new google.maps.LatLng(49.47216, -123.76307),
visible: true
});
infoBox = new InfoBox({latlng: marker.getPosition()});
<!-- var getLat = new InfoBox(); -->
alert(InfoBox.prototype.getPosition);
}
</script>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:50%"></div>
<input type="button" onclick="getLatLong();" />
<div id="letLong"></div>
我想要的是当我点击此getLatLong()
功能时,我必须获得当前定位的标记纬度经度。
请帮助, 感谢
答案 0 :(得分:0)
试试这段代码:
<script type="text/javascript">
var marker=null;
function initialize()
{
var secheltLoc = new google.maps.LatLng(49.47216, -123.76307);
var myMapOptions = {
zoom:15, center:secheltLoc, mapTypeId:google.maps.MapTypeId.ROADMAP
};
var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
marker = new google.maps.Marker({
map:theMap,
draggable:true,
position:new google.maps.LatLng(49.47216, -123.76307),
visible:true
});
}
function getLatLong()
{
alert(marker.position);
}
</script>
我希望这对你有所帮助。