显示位置使用经度/纬度坐标 - Google地图 [英] Display location Using Longitude/Latitude Coordinates - Google Maps
本文介绍了显示位置使用经度/纬度坐标 - Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何输入一组坐标并让Google地图显示位置。这是所有通过JavaScript(即:没有用户界面)完成
How can I input a set of coordinates and have Google maps show a location. This is all to be done through javascript (ie: no user interface)
任何帮助表示赞赏
推荐答案
注意:如果您已经有经度/纬度,请参阅 Alteveer的答案 。
您需要使用地理定位服务才能获取经纬度。 Google地图内置了一个内容:
http:/ /code.google.com/apis/maps/documentation/javascript/services.html#Geocoding
You'll need to need to use a geolocation service to get the latitude/longitude. Google Maps has one built in: http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding
以下是如何使用它的示例:
Here's an example of how to use it:
<!-- 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>
这篇关于显示位置使用经度/纬度坐标 - Google地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文