I am trying to make a small application that accepts the city, state, and geocodes that access the lat / long node. I am currently using the Google Map, ColdFusion, and SQL Server APIs. Basically, the city and state fields are in the database table, and I want to take these places and put a marker on the Google map showing where they are.
This is my geocoding code, and viewing the page source shows that it correctly iterates over my request and places a place ("Omaha, NE") in the address field, but not a marker or map, for that matter, it is displayed on the page:
function codeAddress() { <cfloop query="GetLocations"> var address = document.getElementById(<cfoutput>#Trim(hometown)#,#Trim(state)#</cfoutput>).value; if (geocoder) { geocoder.geocode( {<cfoutput>#Trim(hometown)#,#Trim(state)#</cfoutput>: address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location, title: <cfoutput>#Trim(hometown)#,#Trim(state)#</cfoutput> }); } else { alert("Geocode was not successful for the following reason: " + status); } }); } </cfloop> }
And here is the code to initialize the card:
var geocoder; var map; function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(42.4167,-90.4290); var myOptions = { zoom: 5, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var marker = new google.maps.Marker({ position: latlng, map: map, title: "Test" }); map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); }
I have a job with a map that uses lat / long, which was hardcoded in the database table, but I want to be able to just use the city / state and convert it to lat / long. Any suggestions or directions? Saving lat / long in a database is also possible, but I don't know how to do this in SQL.
javascript coldfusion sql-server google-maps geocoding
knawlejj
source share