hi expert
Scenario: "Get all the cities from sql server then fatch it in javascrtip in order to pass the cities name into geocoder method for taking the makers on google map"
what i did:
i fatched the cities names from Sql server from webservice and then passed it into javascrtip
web service in aspx page(getting the city name from sql server )
<script type="text/C#" runat="server">
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public static string[] GetCitiesbyUser_Extender()
{
System.Data.DataSet dtst = new System.Data.DataSet();
string ses = HttpContext.Current.Session["UserName"].ToString();
USTER.Dal.clsSearch clssearch = new USTER.Dal.clsSearch();
dtst = clssearch.GetAllCitiesByUser(ses);
string[] cntName = new string[dtst.Tables[0].Rows.Count];
int i = 0;
try
{
foreach (System.Data.DataRow rdr in dtst.Tables[0].Rows)
{
cntName.SetValue(rdr["CityName"].ToString(), i);
i++;
}
}
catch { }
finally
{
}
return cntName;
}
</Script>
passed the cities name in javascrtip that is currently on button click in alert box
<script type="text/javascript">
function HandleIT() {
PageMethods.GetCitiesbyUser_Extender(onSucess, onError);
// should be the same name of return type in web service cntName
function onSucess(cntName) {
arr = cntName;
alert(arr.join('\n'));
}
</script>
// button click event in body that will handle this function HandleIT
<asp:Button ID="Button2" runat="server" Text="Button" OnClientClick="HandleIT(); return false;"/>
when i click on this button i will get all the cities in alert box plz download the image below
Image
hope you have seen the image in which i am getting cities are actually the array, i want to convert that array into single string and then pass this cities name one by one from the geocoder method of google map v3 api, the geocoder basically converting the city name into latitude and longitude,
plz see the code of geocoder below
<script type="text/javascript">
var map;
var geocoder;
function initialize() {
var latlng = new google.maps.LatLng(39.91, 116.38);
var myOptions =
{
zoom: 6,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
geocoder = new google.maps.Geocoder();
var address = 'Lahore';
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);
}
});
}
window.onload = initialize;
</script>
<div id ="map" style="width:600px;height:400px;"></div>
The map will only show the city "Lahore" with marker because it`s hard coded yet, now how to convert cities array into single string and pass it one by one from geocoder method in order to get markers on map?