![](/img/trans.png)
[英]Using world Coordinates instead of latitude and longitude coordinates in google maps
[英]Display location Using Longitude/Latitude Coordinates - Google Maps
如何輸入一組坐標並讓Google地圖顯示位置。 這一切都是通過javascript完成的(即:沒有用戶界面)
任何幫助表示贊賞
注意:如果您已經擁有緯度/經度,請參閱Alteveer的答案 。
您需要使用地理定位服務來獲取緯度/經度。 Google地圖內置了一個: http : //code.google.com/apis/maps/documentation/javascript/services.html#Geocoding
以下是如何使用它的示例:
<!-- Placeholder for the Google Map -->
<div id="map" style="height: 512px;">
<noscript>
<!-- http://code.google.com/apis/maps/documentation/staticmaps/ -->
<img src="http://maps.google.com/maps/api/staticmap?center=1%20infinite%20loop%20cupertino%20ca%2095014&zoom=16&size=512x512&maptype=roadmap&sensor=false" />
</noscript>
</div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
// Define the address we want to map.
var address = "1 infinite loop cupertino ca 95014";
// Create a new Geocoder
var geocoder = new google.maps.Geocoder();
// Locate the address using the Geocoder.
geocoder.geocode( { "address": address }, function(results, status) {
// If the Geocoding was successful
if (status == google.maps.GeocoderStatus.OK) {
// Create a Google Map at the latitude/longitude returned by the Geocoder.
var myOptions = {
zoom: 16,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
// Add a marker at the address.
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
try {
console.error("Geocode was not successful for the following reason: " + status);
} catch(e) {}
}
});
</script>
您應該能夠使用緯度/經度初始化地圖,如下所示: https : //developers.google.com/maps/documentation/javascript/tutorial#MapOptions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.