简体   繁体   English

关于Google地图的一个简单问题-居中

[英]An easy question about Google Maps - centering

Every time I embed an iframe from Google Maps it keeps the marker in the middle. 每次我从Google Maps嵌入iframe时,都会将标记保留在中间。

And it does even if there's a tooltip and just CUTS the tooltip data: 即使有工具提示并且仅剪切工具提示数据也可以:

http://jsfiddle.net/V2SVa/ http://jsfiddle.net/V2SVa/

Are there url parameters or something to center the map on the tooltip? 是否有网址参数或其他东西可以使地图位于工具提示的中心?

Well, if you are using the API, then you can issue a call to map.setCenter() . 好吧,如果您使用的是API,则可以发出对map.setCenter()的调用。

If however you are including the maps inline as in your example, then you just need to change the initial starting point. 但是,如果像示例中那样包含内联地图,则只需更改初始起点。

The URL you are using to embed the map is: 您用于嵌入地图的URL为:

http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=
  &q=Museum+near+Washington,+United+States&aq=0
  &sll=40.702863,-74.055748&sspn=0.025669,0.055747&ie=UTF8
  &hq=Museum&hnear=Washington+D.C.,+District+of+Columbia
  &ll=38.913976,-77.05111&spn=0.052698,0.111494&t=h&z=14
  &iwloc=A&cid=4718114823360363843&output=embed

Just a matter of adjusting certain parameters. 只需调整某些参数即可。

The parameters you need to adjust are ll = center location , z = zoom level and spn/sspn = span / screen span . 您需要调整的参数是ll = center locationz = zoom levelspn/sspn = span / screen span Surprisingly awkward to find information on them, but there is some details on the parameters here . 令人惊讶地找不到关于它们的信息,但是这里有一些有关参数的详细信息。 Try fiddling with the ll parameter first if you need to change just the centre. 如果只需要更改中心,请先尝试使用ll参数。

This works for me: 这对我有用:

HTML HTML

<div style="height: 400px; overflow: hidden;">
  <iframe width="425" height="700" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Museum+near+Washington,+United+States&amp;aq=0&amp;sll=40.702863,-74.055748&amp;sspn=0.025669,0.055747&amp;ie=UTF8&amp;hq=Museum&amp;hnear=Washington+D.C.,+District+of+Columbia&amp;ll=38.913976,-77.05111&amp;spn=0.052698,0.111494&amp;t=h&amp;z=14&amp;iwloc=A&amp;cid=4718114823360363843&amp;output=embed"></iframe>
</div>

JQUERY (not even necessary) JQUERY(甚至没有必要)

$("iframe").load(function (){
  $('iframe').css({"height": '400px'});
});

Demo: http://tinker.io/9ace5 演示: http//tinker.io/9ace5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM