Php 如何使用Google Maps API在标记上设置地址
如何在下面的代码中设置地址(带换行符)? 我的代码的相关部分——应该在哪里进行更正——可以在地图上的Php 如何使用Google Maps API在标记上设置地址,php,google-maps,google-maps-api-3,maps,Php,Google Maps,Google Maps Api 3,Maps,如何在下面的代码中设置地址(带换行符)? 我的代码的相关部分——应该在哪里进行更正——可以在地图上的//显示窗口注释行后找到。 目前,格式化是用普通的divs完成的,但我想用谷歌地图信息窗口的标准样式 function initialize() { var mapOptions = { zoom: zoom, center: latglong, scrollwheel: false, streetViewControl: f
//显示窗口
注释行后找到。目前,格式化是用普通的
div
s完成的,但我想用谷歌地图信息窗口的标准样式
function initialize() {
var mapOptions = {
zoom: zoom,
center: latglong,
scrollwheel: false,
streetViewControl: false,
mapTypeControl: false
};
map = new google.maps.Map(document.getElementById('oh-event-map-canvas'), mapOptions);
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: 'my id'
}, function(place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
// display window on the Map
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div><b>' + place.name + '</b><br>' +
'Street <br> Postalcode City <br>Country <br><div class="view-link"> <a target="_blank" href="https://www.google.de//maps/place/adsfasdfadsfadf"> <span>In Google Maps ansehen</span> </a> </div>')
infowindow.open(map, this);
});
}
});
}
函数初始化(){
变量映射选项={
缩放:缩放,
中心:拉特隆,
滚轮:错误,
街景控制:错误,
mapTypeControl:false
};
map=new google.maps.map(document.getElementById('oh-event-map-canvas'),mapOptions);
var infowindow=new google.maps.infowindow();
var service=newgoogle.maps.places.PlacesService(地图);
service.getDetails({
placeId:“我的id”
},功能(地点、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
var marker=new google.maps.marker({
地图:地图,
位置:place.geometry.location
});
//在地图上显示窗口
google.maps.event.addListener(标记'click',函数(){
infowindow.setContent(“”+place.name+”
'+
“街道
邮政编码城市
国家
”)
打开(地图,这个);
});
}
});
}
现在输出如下所示:您可以从
街道地址
城市
状态
邮政编码
国
你说的“但我希望它有正常的样式”是什么意思????expalin better..@scaisEdge我的意思是使用给定的API功能,如格式化的\u地址
,但这设置了地址,没有换行符。
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
function fillInAddress(place) {
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}
// Get each component of the address from the place details
// and fill the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}
<table id="address">
<tr>
<td class="label">Street address</td>
<td class="slimField">
<input class="field" id="street_number" disabled="true" />
</td>
<td class="wideField" colspan="2">
<input class="field" id="route" disabled="true" />
</td>
</tr>
<tr>
<td class="label">City</td>
<!-- Note: Selection of address components in this example is typical.
You may need to adjust it for the locations relevant to your app. See
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
-->
<td class="wideField" colspan="3">
<input class="field" id="locality" disabled="true" />
</td>
</tr>
<tr>
<td class="label">State</td>
<td class="slimField">
<input class="field" id="administrative_area_level_1" disabled="true" />
</td>
<td class="label">Zip code</td>
<td class="wideField">
<input class="field" id="postal_code" disabled="true" />
</td>
</tr>
<tr>
<td class="label">Country</td>
<td class="wideField" colspan="3">
<input class="field" id="country" disabled="true" />
</td>
</tr>
</table>