Reputation: 31
I'have my google map v3 with geolocalisation no problem !
But I would like fetch longitude and latitude to my forms.
Thanks.
Upvotes: 0
Views: 349
Reputation: 2364
If you need long/lat coordinates for a polygon or a single point here is a useful tool: Codepen
JS
var bermudaTriangle;
function initialize() {
var myLatLng = new google.maps.LatLng(33.5190755, -111.9253654);
var mapOptions = {
zoom: 12,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.RoadMap
};
var map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
var triangleCoords = [
new google.maps.LatLng(33.5362475, -111.9267386),
new google.maps.LatLng(33.5104882, -111.9627875),
new google.maps.LatLng(33.5004686, -111.9027061)
];
// Construct the polygon
bermudaTriangle = new google.maps.Polygon({
paths: triangleCoords,
draggable: true,
editable: true,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
bermudaTriangle.setMap(map);
google.maps.event.addListener(bermudaTriangle, "dragend", getPolygonCoords);
google.maps.event.addListener(bermudaTriangle.getPath(), "insert_at", getPolygonCoords);
google.maps.event.addListener(bermudaTriangle.getPath(), "remove_at", getPolygonCoords);
google.maps.event.addListener(bermudaTriangle.getPath(), "set_at", getPolygonCoords);
}
function getPolygonCoords() {
var len = bermudaTriangle.getPath().getLength();
var htmlStr = "";
for (var i = 0; i < len; i++) {
htmlStr += bermudaTriangle.getPath().getAt(i).toUrlValue(5) + "<br>";
}
document.getElementById('info').innerHTML = htmlStr;
}
Upvotes: 0
Reputation: 937
Well if you need latitude and longitude everywhere you move you mouse you can do it like this:
google.maps.event.addListener(map,'mousemove', function(event) {
console.log(event.latLng);
$("#inputFormLat").val(event.latlng.lat()); //your input text box (i used jquery here to select it and set its value)
$("#inputFormLon").val(event.latlng.lng());
});
If you have any doubt pls ask
Regards, Suyash
Upvotes: 1
Reputation: 108
You can try Google markers for it. Here is whole documentation to it. https://developers.google.com/maps/documentation/javascript/examples/marker-simple
If I understand your question correctly, This is related to what you are looking for: How do you click on a map and have latitude and longitude fields in a form populated?
Upvotes: 1