I am curently working with google maps and I have a method that creates markers on google maps. The method gives the info for the markers. one part of this info is the longtitude and lattitude for the marker. The longtitude and lattitude are retreived from a zip code via a function in javascript. however when I return the longtitude and Lattitude it says it contains nothing.
It gets multiple zip codes and should return multiple longtitudes and lattitudes
My code:
This adds the markers.
void AddMarkerTimer(object sender, EventArgs e)
{
try
{
this.Document.InvokeScript("addMarker", new string[] { this.Document.InvokeScript("getLatFromPost", new string[] { delictMarkers[MarkerIndex].PostalCode }) + "", this.Document.InvokeScript("getLonFromPost", new string[] { delictMarkers[MarkerIndex].PostalCode }) + "", "marker" + MarkerIndex, MarkerIndex + "" });
MarkerIndex++;
}
catch(ArgumentOutOfRangeException ax){
MessageBox.Show(ax.ToString());
}
if (MarkerIndex == delictMarkers.Count - 1)
{
MarkerTimer.Stop();
}
}
This should return a longtitude and lattitude (javascript).
function getLatFromPost(post) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: post },
function (results_array, status) {
var s;
s = results_array[0].geometry.location.lat();
//alert(s);
// Check status and do whatever you want with what you get back
// in the results_array variable if it is OK.
return s;
});
}
function getLonFromPost(post) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: post },
function (results_array, status) {
var s;
s = results_array[0].geometry.location.lng();
alert(s);
// Check status and do whatever you want with what you get back
// in the results_array variable if it is OK.
return s;
});
}
And this part adds it on the map(javascript).
function addMarker(x, y, titleMarker, index) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(x, y),
map: map,
title: titleMarker,
icon: delict,
index: index
});
google.maps.event.addListener(marker, "click", function (event) {
showMarkerContextMenu(event.latLng, index, titleMarker);
});
marker.set("index", index);
markerList[index] = marker;
//marker.setMap(map);
}
I hope it is clear what my problem is. Thank you in advance for your attention.