gpt4 book ai didi

google-maps - 根据城镇名称聚焦谷歌地图

转载 作者:行者123 更新时间:2023-12-04 07:08:15 27 4
gpt4 key购买 nike

我有一个城镇名称、gmap 模块和 plg。我想通过输入城镇名称而不是经度和纬度来在 gmap 中聚焦所需位置。在 Joomla 1.5.x 中有什么方法可以做到这一点。

提前致谢
纳文

最佳答案

您将需要一个地理编码器来根据城市名称获取位置。对 Joomla 一无所知,但这里是使用 JavaScript 的示例。

的HTML

<div id='myMap' style="position:relative; width:740px; height:400px;"></div>

剧本

您必须填写 Google API Key 和您想要的城市
<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=XXXXX">
</script>

<script type="text/javascript">
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function')
{ window.onload = func; }
else {
window.onload = function()
{ oldonload(); func(); }
}
}

var map = null;
var geocoder = null;

addLoadEvent(initialize);

function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("myMap"));
map.setCenter(new GLatLng(-12.08, -53.08), 4);
map.addControl(new GSmallMapControl());
map.addControl(new GOverviewMapControl());
geocoder = new GClientGeocoder();
showAddress('YourCity, YourCountry');
}
}

function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
$("#myMap").hide();
} else {
map.setCenter(point, 8);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
</script>

关于google-maps - 根据城镇名称聚焦谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/772435/

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