如何使用iframe来居中Google地图?

时间:2017-05-27 12:17:15

标签: php google-maps dictionary iframe

我搜索到处都是,但我找不到一个正确的方法来集中我的谷歌地图。我正在使用iframe。该网站是分类广告,因此每个广告创建不同的位置。

我的代码是这样的:

<iframe frameborder="0" noresize="noresize" 
height="420px" width="100%" 
src="<?=Route::url('map')?>?height=400&id_ad=<?=$ad->id_ad?>&controls=0&zoom=<?=Core::config('advertisement.map_zoom')?>&get.Center=setCenter(<?=$ad->latitude?>,<?=$ad->longitude?>)">

我也尝试过这个:

&center=setCenter(<?=$ad->latitude?>,<?=$ad->longitude?>)

&center=map.setCenter({lat:<?=$ad->latitude?>,lng:<?=$ad->longitude?>})

此外,

setCenter(latlng:LatLng|LatLngLiteral)
setCenter(latlng:<?=$ad->latitude?><?=$ad->longitude?>|<?=$ad->latitude?><?=$ad->longitude?>Literal)

但是我无法在中心做到正确,它要么离左边更远,要么远离左上角。但是,如果您打开页面并直接进入“地图”选项卡,您将获得它的中心位置,但如果您等待,则点击它不会位于中心的点击地图。

如果我的解释不是很清楚,请点击此处:https://linkinads.com/airline-job-aviation-sales-marketing-sales-representative-sales-manager/landmark-group-job-hiring-in-retail-group.html

请咨询。感谢

1 个答案:

答案 0 :(得分:1)

放置iframe,它会自动居中定位。 例如:只需访问谷歌地图(https://www.google.com/maps/

在搜索栏中输入您的位置

enter image description here

现在按侧面菜单按钮

enter image description here

点击分享嵌入地图

enter image description here

弹出一个弹出窗口。点击嵌入地图然后你就可以看到i-frame

enter image description here

或者如果你想将整个iframe居中,那么你可以将iframe放在div中并给它造型!

快乐编码:)