我想要的是拥有一张地图,当我在某个位置设置标记时,我会得到它的经度和经度......请告诉我我的代码有什么问题?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>geoloaction</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
$(function(){
var latlng=new google.maps.LatLng(35.6771389,10.0972400);
var map=new google.maps.Map(document.getElementById('gmap'),{
zoom:13,
center:latlng,
mapTypeld:google.maps.MapTypeld.ROADMAP });
var marker=new google.maps.Marker({
position:latlng,
map:map,
title:'bougez ce cuseur' ,
draggable: true });
var geocoder=new google.maps.Geocoder();
google.maps.event.addListener(marker,'drag',function(){
setPosition(marker); });
return false; });
function setPosition(marker){
var pos=marker.getPosition();
$(document.getElementById('Lat')).val(pos.lat());
$(document.getElementById('Lng')).val(pos.lng());
}
</script>
</head>
<body>
<div id="gmap" style="width:100%;height:400px;"></div>
</body>
答案 0 :(得分:1)
这是解决方案https://jsfiddle.net/m97o308u/
不是MapTypeld
而是MapTypeId
您应该将此行mapTypeld:google.maps.MapTypeld.ROADMAP
更改为mapTypeId:google.maps.MapTypeId.ROADMAP