I have a google map that displays my current location and when I click on the map a new marker is added that displays the latitude and longitude in an infowindow. I'm happy with that.
What I want to happen is for that latitude and longitude to be entered into a form I have on the same page with details about that location. That info will then be sent to a database.
This is the javascript:
var map;
var marker2;
var infowindow2;
var infowindow;
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition, placeMarker, showError);
}
else
{
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position)
{
lat2 = position.coords.latitude;
lon = position.coords.longitude;
latlon = new google.maps.LatLng(lat2, lon)
mapholder = document.getElementById('mapholder')
var mapProp =
{
center: latlon, zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
navigationControlOptions:{style: google.maps.NavigationControlStyle.SMALL}
};
map = new google.maps.Map(document.getElementById("mapholder"),mapProp);
var marker = new google.maps.Marker({ position: latlon, map:map, title: "You are Here"});
marker.setMap(map);
infowindow2 = new google.maps.InfoWindow({ content:"You are Here!" + "<br>Click on desired location to generate latitute and longitude coordinates;" + "<br>Click 'Send' to enter Latitude and Longitude co-ordinates into form"});
infowindow2.open(map,marker);
google.maps.event.addDomListener(window, 'load', getLocation);
google.maps.event.addListener(map, 'click', function(event)
{
placeMarker(event.latLng);
});
}
function placeMarker(location)
{
if (!marker2)
{
marker2 = new google.maps.Marker({ position: location, map: map, icon: 'Icon/aed4.jpg' });
}
else
{
marker2.setPosition(location);
}
google.maps.event.addListener(marker2, 'click', function (event)
{
document.getElementById("latbox").value = event.lat();
document.getElementById("lngbox").value = event.lng();
});
infowindow = new google.maps.InfoWindow({ content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng() });
infowindow.open(map, marker2);
infowindow2.close(map, marker2);
google.maps.event.addDomListener(window, 'load', showPosition);
}
google.maps.event.addDomListener(window, 'load', placeMarker);
infowindow.close(map, marker2);
This is the form I want to place it in:
<div id="formlocation">
<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="buildingLbl" runat="server" Text="Building Name:"></asp:Label>
</td>
<td>
<asp:TextBox ID="buildingTxt" runat="server"></asp:TextBox>
</td>
</tr>
Latitude:<input size="20" id="latbox" type="text" name="lat" />
<br />
Longitude:<input size="20" id="lngbox" type="text" name="lng" />
<br />
I tried putting them into a textbox but couldn't get that working either.
Also, will I be able to send the info from the input area into SQL the same as the textbox?
I thought I found the answer here but cant figure what I'm doing wrong - hopefully there's a nice simple solution - I'm a novice... All help appreciated.
I was thinking something like this website EXAMPLE. I will only have 1 marker that can be moved by clicking on map and this changes the values in the latitude and longitude fields.
I was adding in screenshot of what I have so far but I cant until I have 10 reputations... I want the coords to populate the fields as the marker is moved by clicking on the map. I know I have in the InfoWindow to click 'Send' to enter co-ordinates into form but ideally it will change as you move the marker by clicking on the map.
I want the Latitude and Longitude values from the infoWindow to go into the form. I have two fields for Latitude and Longitude in my example but that is from me trying to get the values into a TextBox and input field.
There should be a 'Submit' button at the bottom of the form that sends all the information to a database (SQL).
Hope this helps explain what I'm after...