Hello everybody,
I''m working with Version 3 of Google Maps JavaScript API, and I have
the next code:
In a layout of my application:
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/
libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?
sensor=false"></script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(28.142722, -15.448609);
//Creatin a MapOptions object with tthe required properties
var myOptions = {
zoom: 3,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
//Creating the map
var map = new google.maps.Map(document.getElementById("mapilla"),
myOptions);
// add the marker itself
var marker = new google.maps.Marker({
position: latlng,
map: map,
draggable: true
});
}
function add_marker(map, lat, lng) {
var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
var myOptions = {
zoom: 10,
center: point,
//mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN,
position: google.maps.ControlPosition.TOP_RIGHT
},
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
position: google.maps.ControlPosition.TOP_LEFT
},
};
var map = new google.maps.Map(document.getElementById("mapilla"),
myOptions);
// add the marker itself
var marker = new google.maps.Marker({
position: point,
map: mapilla,
draggable: true
});
google.maps.event.addListener(marker, ''position_changed'',
function()
{
var darwin = new google.maps.LatLng(marker.getPosition());
$(''input:text[name=event[lng]]'').val(marker.getPosition().lng());
$(''input:text[name=event[lat]]'').val(marker.getPosition().lat());
//document.getElementById("Longitud").innerHTML
marker.getPosition().lng();
//document.getElementById("Latitud").innerHTML
marker.getPosition().lat();
//document.getElementById("lng").value
marker.getPosition().lng();
//document.getElementById("lat").value
marker.getPosition().lat();
//map.setZoom(1);
map.setCenter(marker.getPosition());
});
}
</script>
<body onload="initialize()">
.
.
.
</body>
in the view for the form:
<tr>
<th scope="row"><%=
I18n.t("tog_conclave.fields.lat") %></th>
<td nowrap="nowrap"><%=f.text_field :lat,
:class=>"fieldbox" %></
td>
</tr>
<tr>
<th scope="row"><%=
I18n.t("tog_conclave.fields.lng") %></th>
<td nowrap="nowrap"><%=f.text_field :lng,
:class=>"fieldbox" %></
td>
</tr>
and showing the map with this:
<div id="mapilla"></div>
and the problem that i have is that i want to take the lng and lat
from the marker but i can''t.
How can I resolve it?
Thanks for your help.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.