PHP-使用位置名称在Google地图中标记/标记位置
作者:互联网
是否可以使用位置名称在Google地图中动态标记位置.
客户将通过rss feed向我们提供位置名称.我们将使用php脚本(不必担心)来获取该位置,然后在Google Map中对其进行标记.
假设我们有以下地址:韦斯顿镇娱乐部门Weston Town Recreation Department 20 Alphabet Ln,Weston,MA(781),那么我们必须在googel地图中进行标记
我不太了解如何发布或标记此标记,并且由于我是此Google地图的新手而在网页中动态显示
请引导我解决这个问题.
我也想在鼠标悬停在Google地图上的标记时向弹出窗口中添加一些详细信息-请为此也提出解决方案
解决方法:
您需要将地址设置为Geocode,然后使用result [idx] .geometry.location设置标记. (Google地图地理编码页面上的an example可以帮助您入门.)
如果此处更改或不再存在,则在此处添加了Google代码.
var geocoder, map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
<body onl oad="initialize()">
<div id="map_canvas" style="width: 320px; height: 480px;"></div>
<div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div>
</body>
标签:google-maps,google-maps-api-3,php 来源: https://codeday.me/bug/20191209/2096052.html