ページ内のフォームと Google マップをカラーボックスで開く 他のページからロードする マップ内のドラッグ ボタンを移動するときに、他のページ フォームの値を変更する
フォームページ:form.php
<form action="ajax-trades/submit-edit.php" method="POST">
<div id="address"></div>
<input type="hidden" name="target" id="target" value="<?php echo $row['gmap']; ?>">
<input type="submit" onclick="window.scrollTo(0, 200);" value="submit" class="button" />
</form>
そして、これは他のページにGoogleマップをロードするためのjqueryです:
<script type="text/javascript">
$(function(){
function objToString (obj) {
var str = '';
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
str += obj[p] + ',' ;
}
}
return str;
}
$("#test").gmap3({
marker:{
latLng: [35.712926551232044, 51.40896647885131,],
options:{
draggable:true
},
events:{
dragend: function(marker){
var position = (marker.getPosition());
//$("#map").html(position[2]);
//var stingposition = objToString (position);
$("#address").html('<input type="hidden" name="map" value="' + position.toString() + '" />');
$(this).gmap3({
getaddress:{
latLng:marker.getPosition(),
callback:function(results){
var map = $(this).gmap3("get"),
infowindow = $(this).gmap3({get:"infowindow"}),
content = results && results[1] ? results && results[1].formatted_address : "no address";
if (infowindow){
infowindow.open(map, marker);
infowindow.setContent(content);
} else {
$(this).gmap3({
infowindow:{
anchor:marker,
options:{content: content}
}
});
}
}
}
});
}
}
},
map:{
options:{
zoom: 14
}
}
});
});
</script>
この行だけが機能するのに重要ですが、機能しません!
$("#address").html('<input type="hidden" name="map" value="' + position.toString() + '" />');