I'm trying to do something like this:
Where I have form on right half of screen and marker centered on left side of screen. Moving map - marker will stay in center of left side, and I will get LatLng
from the marker(Visualy, but that is offseted center) on Map move.
For now I have centered marker on map and I can move map and get LatLng from center.
This is script that do that:
var map = null;
var marker;
function showlocation() {
if ("geolocation" in navigator) {
/* geolocation is available */
// One-shot position request.
navigator.geolocation.getCurrentPosition(callback, error);
} else {
/* geolocation IS NOT available */
console.warn("geolocation IS NOT available");
}
}
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
};
function callback(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
document.getElementById('default_latitude').value = lat;
document.getElementById('default_longitude').value = lon;
var latLong = new google.maps.LatLng(lat, lon);
map.setZoom(16);
map.setCenter(latLong);
}
// google.maps.event.addDomListener(window, 'load', initAutocomplete);
function initAutocomplete() {
var mapOptions = {
center: new google.maps.LatLng(42.4405026181028, 19.24323633505709),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"),
mapOptions);
google.maps.event.addListener(map, 'center_changed', function () {
document.getElementById('default_latitude').value = map.getCenter().lat();
document.getElementById('default_longitude').value = map.getCenter().lng();
});
$('<div/>').addClass('centerMarker').appendTo(map.getDiv())
.click(function () {
var that = $(this);
if (!that.data('win')) {
that.data('win', new google.maps.InfoWindow({
content: 'this is the center'
}));
that.data('win').bindTo('position', map, 'center');
}
that.data('win').open(map);
});
And I have marker centered in CSS:
#map .centerMarker {
position: absolute;
/*url of the marker*/
background: url(http://maps.gstatic.com/mapfiles/markers2/marker.png) no-repeat;
/*center the marker*/
top: 50%;
left: 50%;
z-index: 1;
/*fix offset when needed*/
margin-left: -10px;
margin-top: -34px;
/*size of the image*/
height: 34px;
width: 20px;
cursor: pointer;
}
I just need to offset all of this for 25% to the left from the center and keep 50% of right screen for the form.