I have spent a few hours looking at this and cannot find the solution I am after. I know I am missing something, but could do with a little help.
In essence I have a Classic ASP page with a recordset holding addresses. I want to pull those addresses into the page (with repeat region). Done that bit and have the string Google expects with the correct info.
<script>var map_locations = [{"lat":52.954145,"lng":-4.101083,"title":"Nice House in Wales","street":"Prenteg, Porthmadog, LL49 9SR","price":"55,500"}]</script>
However, I want to replace "lat" etc with the following:
<script>var map_locations = [{"address":"<%=(rsLocations.Fields.Item("locPostCode").Value)%>","title":"Nice house in Wales","street":"Prenteg, Porthmadog, LL49 9SR","price":"55,500"}]</script>
- I do not hold the Lat/Lng of the addresses
- I have gone through Google's API documentation on GeoCoding. Found something of use, but cannot figure out how to get my "binding" of "postcode" into the address function inside of my JS file. (link: https://developers.google.com/maps/documentation/javascript/geocoding).
Here is what Google suggests I do based on the link above. Google GeoCoding
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
<body onload="initialize()">
<div id="map_canvas" style="width: 320px; height: 480px;"></div>
<div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div>
</body>
Now, Google's documentation uses a input variable of "address" so you can use this with the following:
var address = document.getElementById("address").value;
My question is, how do I get recordset binding to be the address? ASP and JS file's don't mix well and unsure of how to get it into the address for geocoding to work properly.
My JS file (global.js) contains the following that works if I send through Lat/Lngs and it gives nicely styled markers and info boxes for the user to interact with.
JS File that deals with writing Google Map stuff
var map;
function initializePropertiesMap() {
if($('#map_canvas').length == 0)
return;
var myLatlng = new google.maps.LatLng(52.954145,-4.101083);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var infowindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
$.each(map_locations, function(key, value) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(value['lat'], value['lng']),
map: map,
icon: 'css/images/marker.png',
scrollwheel: false,
streetViewControl:true,
title: value['title']
});
var link = "link";
google.maps.event.addListener( marker, 'click', function() {
// Setting the content of the InfoWindow
var content = '<div id="info" class="span5"><div class="row">' + '<div class="span2"><img src="css/images/houses/house_'+(key+1)+'.jpg" class="thumbnail" style="width:135px"/></div>' + '<div class="span3"><h3>' + value['title'] + '</h3><h6>' + value['street'] + '</h6>' + '<strong>£' + value['price'] + '</strong>' + '<p><a href="listing-detail.asp">Read More >></a></p>' + '</div></div></div>';
infowindow.setContent(content );
infowindow.open(map, marker);
});
});
}
Having tweaked with this, I cannot get it to work and wondered if anyone has any advice for me?
Thanks Nick
UPDATE
Just thought I'd mention that I have tried this:
var address = <%=rsLocations.Fields.Item("locPostcode").value%>;
That obviously won't work as the JS file errors.