Is it possible to center the card in a fixed position (lat lng) - 100px?

I want to say that I would like to focus the map on a fixed position:

map.setCenter(markerCliccato.getPosition()); 

and smaller (Y axis) 100 pixels down. Is it possible? Or do I need Lat / Lng of this "virtual" point?

This is because I have a very high InfoWindow height and I need to put it 100px on top of the map! It is not possible to use the "margin" in an infowindow because it can cause problems with another marker on the map.

Example

I have this point as Lat / Lng: https://maps.google.com/?q=54.572062,-3.038818

But I want to focus the map on https://maps.google.com/?q=54.486793,-3.042046 (which is more or less 100 pixels below my point on the map)

+1
source share
1 answer

ok, I need to send photos :)

it's up to a click

before

and this is after

after

there is no gray area, the whole map is displayed.

Also, to see the marker, you must allow the site to track your location.

 function offsetCenter(latlng, offsetx, offsety) { var scale = Math.pow(2, map.getZoom()); var nw = new google.maps.LatLng( map.getBounds().getNorthEast().lat(), map.getBounds().getSouthWest().lng()); var worldCoordinateCenter = map.getProjection().fromLatLngToPoint(latlng); var pixelOffset = new google.maps.Point((offsetx / scale) || 0, (offsety / scale) || 0) var worldCoordinateNewCenter = new google.maps.Point( worldCoordinateCenter.x - pixelOffset.x, worldCoordinateCenter.y + pixelOffset.y); var newCenter = map.getProjection().fromPointToLatLng(worldCoordinateNewCenter); map.setCenter(newCenter); } 

see here: http://jsfiddle.net/RASG/vA4eQ/

tested with FF 15, IE 9 and Chrome 21

+2
source

Source: https://habr.com/ru/post/1445196/


All Articles