Got it:
Had to remove the drag-feature from the marker sinde the drag-event didn`t changed the field-values.
Maybe this could be added by additional JS, but this works for me.🙂
Designer: Custom-Item
<div id="panel"><input id="address" type="textbox" value="Ausflusgzeil suchen" /> <input id="geocode" type="button" value="suchen" /></div>
<div id="googleMap" style="width: 800px; height: 250px;"> </div>
<div id="leftContainer" style="float:left;padding-right:20px;">
<span>Lat:</span>
<br><input type='text' name='lat' id='lat' value='' />
</div>
<div id="rightContainer" style="float:left;">
<span>Lng:</span>
<br><input type='text' name='lng' id='lng' value='' />
</div>
Setup: JS Code:
jQuery(document).ready(function(jQ) {
var map;
var marker;
jQ('#geocode').click(codeAddress);
function initialize() {
var mapOptions = {
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(52.283, 10.523),
mapTypeControl: true,
mapTypeControlOptions: {
mapTypeIds: [
google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.TERRAIN,
google.maps.MapTypeId.SATELLITE,
google.maps.MapTypeId.HYBRID ],
position: google.maps.ControlPosition.LEFT_BOTTOM ,
style: google.maps.MapTypeControlStyle.DEFAULT },
zoomControl: true,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_CENTER },
disableDoubleClickZoom: false,
scrollwheel: true,
scaleControl: false,
streetViewControl: false,
rotateControl: false
};
map = new google.maps.Map(jQ('#googleMap')[0], mapOptions);
geocoder = new google.maps.Geocoder(); // this line was missing
// This event listener will call addMarker() when the map is clicked.
map.addListener('click', function(event) {
document.getElementById('lat').value = event.latLng.lat();
document.getElementById('lng').value = event.latLng.lng();
addMarker(event.latLng);
});
} //end function
function codeAddress() {
var address = jQ('#address').val();
geocoder.geocode({ 'address': address }, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(14);
//var marker = new google.maps.Marker({
// map: map,
// position: results[0].geometry.location,
// draggable: true
//});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
function addMarker(location) {
if (!marker) {
marker = new google.maps.Marker({
position: location,
//draggable: true,
map: map
});
} else {
marker.setPosition(location);
}
markers.push(marker);
}
google.maps.event.addDomListener(window, 'load', initialize);
});
Setup: JS Files
https://maps.googleapis.com/maps/api/js?v=3.exp