【问题标题】:How to center the Google Map by using Iframe?如何使用 iframe 将谷歌地图居中?
【发布时间】:2017-05-27 12:17:15
【问题描述】:

我到处搜索,但找不到正确的方法来使我的谷歌地图居中。我正在使用 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

请指教。谢谢

【问题讨论】:

  • 我无法使用从 google.com/maps 获取的 iframe,因为用户正在创建或每个用户位于不同的位置。例如,一位用户从迪拜发布,第二位用户从菲律宾发布……然后是俄罗斯……!所以我不能把迪拜或俄罗斯作为我地图坐标的中心。
  • 地图截图 我希望标记在中心!谢谢i.imgur.com/40HzdHj.png

标签: php google-maps dictionary iframe


【解决方案1】:

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

在搜索栏中输入您的位置

现在按下侧面菜单按钮

点击分享嵌入地图

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

或者,如果您想将整个 iframe 居中,则可以将 iframe 放在 div 中并为其设置样式!

快乐编码:)

【讨论】:

  • 感谢您的信息,但我的板是分类广告。每个用户都有不同的协调等等。例如,来自英国的某个人发布了他的地址......然后另一个来自纽约......
  • 好的!假设自动将地图居中......所以它会像这样吗? src="=Route::url('map')?>?height=400&id_ad==$ad->id_ad?>&controls=0&zoom==Core::config('advertisement.map_zoom') ?>">
  • 是的,你可以试试。在我的情况下,它就像@dk-pramis
  • 我会检查的
  • 还是同一个兄弟
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多