gpt4 book ai didi

google-maps - 如何在仅包含城市名称的谷歌地图 API 上获取城市的 Lat、Alt

转载 作者:行者123 更新时间:2023-11-28 10:33:09 25 4
gpt4 key购买 nike

我试图仅通过城市名称来定位城市的纬度和经度。

我尝试仅使用 Gmaps API,并避免使用 google 提供的地理定位网络服务。

最佳答案

进行搜索后,您可以通过 place.Point.coordinates 获取坐标

示例:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps API Sample</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"></script>
<script type="text/javascript">

var map;
var geocoder;

function initialize() {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(34, 0), 1);
geocoder = new GClientGeocoder();
}

// addAddressToMap() is called when the geocoder returns an
// answer. It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response) {
map.clearOverlays();
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
} else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
marker = new GMarker(point);
map.addOverlay(marker);
--> // here you get the coordinates of the founded point
marker.openInfoWindowHtml('<b>Coordinates:</b> ' + place.Point.coordinates);
}
}

// showLocation() is called when you click on the Search button
// in the form. It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
var address = document.forms[0].q.value;
geocoder.getLocations(address, addAddressToMap);
}

// findLocation() is used to enter the sample addresses into the form.
function findLocation(address) {
document.forms[0].q.value = address;
showLocation();
}

</script>
</head>
<body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;">
<!-- Creates a simple input box where you can enter an address
and a Search button that submits the form. //-->
<form action="#" onsubmit="showLocation(); return false;">
<p>
<b>Search cities:</b>
<input type="text" name="q" value="" class="address_input" size="40" />
<input type="submit" name="find" value="Search" />

</p>
</form>
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>​

关于google-maps - 如何在仅包含城市名称的谷歌地图 API 上获取城市的 Lat、Alt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2440913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com