I have this script that is working. I can drag the marker and it will populate two text input fields with Longitude and Latitude. I have the variable "address" which holds a state and county. How should I alter my code to make it work off the address variable rather than the static latitude and longitude variables. So initially I want the map to center in the middle of the address location.
function selectState(state_id){
if(state_id!="-1"){
loadData('city',state_id);
var e = document.getElementById("state");
var stateloc = e.options[e.selectedIndex].value;
var address = state_id + stateloc;
var $latitude = document.getElementById('latitude');
var $longitude = document.getElementById('longitude');
var latitude = 35.00636021320537
var longitude = -53.46687316894531;
var zoom = 12;
var LatLng = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
zoom: zoom,
center: LatLng,
panControl: false,
zoomControl: true,
scaleControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map'),mapOptions);
var marker = new google.maps.Marker({
position: LatLng,
map: map,
title: 'Drag Me!',
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function(marker){
var latLng = marker.latLng;
$latitude.value = latLng.lat();
$longitude.value = latLng.lng();
});
}else{ $("#city_dropdown").html("<option value='-1'>Select city</option>");
}
}
html
<li>
<label for="lat">Latitude:</label>
<input id="latitude" placeholder="latitude" name="lat" type="text" class="text" />
</li>
<li>
<label for="lon">Longitude:</label>
<input id="longitude" placeholder="longitude" name="lon" class="text" type="text"/>
</li>
<div id="map" style="width: 460px; height: 350px;"></div>