我用這個片段,並適用於所有情況。
<body>
<div id="mainpanel" style="float:left; background-color:#fff; width:75%;">
<div style="display:none;" id="lat">hhh</div><div style="display:none;" id="lon">hhh</div>
<script>
var x=document.getElementById("lat");
var y=document.getElementById("lon");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
x.innerHTML=position.coords.latitude;
y.innerHTML=position.coords.longitude;
loadScript();
}
function initialize()
{
var xval=document.getElementById("lat").innerHTML;
var yval=document.getElementById("lon").innerHTML;
var mapProp = {
center: new google.maps.LatLng(xval,yval),
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
function loadScript()
{
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false&callback=initialize";
document.body.appendChild(script);
}
//window.onload = loadScript;
</script>
<form>
<input class="boxinput" type="text" class="form-control" placeholder="Phone" id="" name=""/>
</form>
<div class="serchbox"></div>
<div id="googleMap" style="width:960px;height:804px;"></div>
</div>
</body>
請你能提供你正在使用的古吉拉特邦的經緯度嗎? – 2012-03-06 05:26:17
即將使用的古吉拉特邦,艾哈邁達巴德的緯度和經度是緯度= 23.00和經度= 72.00 – 2012-03-06 05:30:16
[Google Places API不會爲印度返回任何結果]的可能重複(http://stackoverflow.com/questions/9477512/google- api-not-returning-any-results-for-india) – 2012-03-06 06:43:07