Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API V3: Bound world to fit area and disable map repeat

Setting the center: new google.maps.LatLng(0,0) will set the center of the world. And zoom: 1 makes the default zoom to whole world.

Question is, given the size 616px by 310px of the map how can we modify/resize the map so it fits the given size nicely. For example only one instance of world gets shown and bottom of the map will be the bottom of Africa. So subsequently world map will not repeat. To be precise making our map bound like this:

enter image description here

This is what I have got so far: enter image description here

like image 716
Mazzi Avatar asked Nov 26 '12 22:11

Mazzi


People also ask

How do I restrict Google Maps API?

Set an application restriction for an API keyGo to the Credentials page. Select the API key that you want to set a restriction on. The API key property page appears. Under Key restrictions, select Application restrictions.

Is Google Maps API no longer free?

Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).

How do you make Google Maps smooth?

If one just sets the zoom on double click, the map is suddenly on that zoom level, without any smooth transition. Zooming in only one level further than the current level, Google Maps shows a nice smooth transition.

How do I pan Google Maps?

Panning and Zooming with Google Maps To move the map click and hold the left mouse button and drag the map to a new place. You can also move the map North, South, East or West using the pan arrows. These can be found on the top left hand corner of the map.


1 Answers

The 'picture' of the whole world has a constant size at a given zoom level. For zoom level 1 it's 512 pixels, for zoom level 2 1024, 3 = 2048 , 4 = 4096 etc ...

To fit the whole world without repeating it you need to have a map div that is smaller than the picture of the whole world at this zoom level, otherwise it won't work.

For zoom level 1 the map would need to 512 to fit ideally and less not to wrap.

https://output.jsbin.com/vabago is a sample that shows the world width at given zoom levels and logs it to the console. It also resizes the map to fit the whole world when you zoom in (a silly thing to do usually, but here it just shows how this works).

HTH

like image 77
kaskader Avatar answered Oct 08 '22 15:10

kaskader