I was wondering if it is possible to offset the center of a map in Google maps api v3. I would like to control this offset in pixels, since by lat and lng seems wrong and very difficult to predict.
I just need to place a marker, and then offset the center by 250px so I can place some other content in the middle of the map.
Hope someone can help!
Easily create your styleThe new Google Maps APIs Styling Wizard helps you to create a map style in a few clicks. Use one of our pre-built styles or create your own style from scratch.
With style options you can customize the presentation of the standard Google map styles, changing the visual display of features like roads, parks, businesses, and other points of interest. As well as changing the style of these features, you can hide features entirely.
The first step is to go to the Add or Edit Map section and then to the 'Map Style Setting' section. Then, select any feature type, type, and color you want. The third step is to save the map to your computer and then launch it in the browser.
Found this question when researching and thought I should provide an answer:
function map_recenter(latlng,offsetx,offsety) { var point1 = map.getProjection().fromLatLngToPoint( (latlng instanceof google.maps.LatLng) ? latlng : map.getCenter() ); var point2 = new google.maps.Point( ( (typeof(offsetx) == 'number' ? offsetx : 0) / Math.pow(2, map.getZoom()) ) || 0, ( (typeof(offsety) == 'number' ? offsety : 0) / Math.pow(2, map.getZoom()) ) || 0 ); map.setCenter(map.getProjection().fromPointToLatLng(new google.maps.Point( point1.x - point2.x, point1.y + point2.y ))); }
If your Google maps variable isn't map
use the following call function reference:
function map_recenter(map,latlng,offsetx,offsety) { ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With