当前位置: 动力学知识库 > 问答 > 编程问答 >

I want to zoom & center a Google map enough to fit a whole block

问题描述:

Given an address, is there a way to fetch a static Google map with certain parameters in order to show the entire block including the surrounding streets?

This is the result I'm trying to achieve (I just centered and zoomed manually from Google Maps to make the screenshot):

But when requesting via Static Maps API, using zoom 17 is too far:

and using zoom=18 is too close:

Not to mention that I can't figure out how to do the right centering of the map.

网友答案:

I don't think there's an out-of-the-box way of doing this. There are plenty of possibilities for which block you want to show.

Some complications (there are more, I bet) include:

  • if you're in a street corner, which of the 4 blocks should the sprite be panned to?
  • if the address is a park?
  • if your block has an irregular shape? (even with the rectangular-like blocks in NYC it is complex enough due to their rotation on North axis)

If you have the origin latitude and longitude instead of the address, you could try using the &visible=latLng2 argument for the Static Maps URL, where latLng2 is a modified version of origin including a delta (probably ~0.002 degrees) to make it look similar to your idea. This argument cannot be used with a given zoom.

Before:

After:

Maybe your best option is to go with some calculations in the middle (like Google Geo services to know which is the street around the corner, etc)

分享给朋友:
您可能感兴趣的文章:
随机阅读: