私は学校のプロジェクトをやっています。簡単なウェブサイトを作成し、そこにグーグルマップを追加し、テキストファイルから100の異なるアドレスを読んで、マーカーでグーグルマップにそれらの場所を表示する必要があります。
今、私はグーグルマップのチュートリアルで見たjavascriptを使ってASP.netページにグーグルマップを追加しようとしています。そして、私がアドレスを座標に変換しなければならないという問題があります。そのために私は使用しています
function addAddressToMap(response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
}
else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(place.address + '<br>' + '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
}
}
// showLocation() is called when you click on the Search button
// in the form. It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
var address = "izmit";
var address2 = "ağrı";
geocoder.getLocations(address, addAddressToMap);
geocoder.getLocations(address2, addAddressToMap);
}
これらの機能とそれらは正常に動作しています。しかし、ここでの私の問題は、テキストファイルからこれらのアドレス情報を取得する必要があるということです。しかし、それらを取得するには、いくつかの異なるコードを使用する必要があります。そして、C#コードを使用してサーバー側で作成したいと思います。しかし、サーバー側でいくつかのコードを記述してから、アドレスとしてHTML側に何かを返す方法がわかりません。ご理解頂けるとありがたいです。助けてくれてありがとう。
アップデート:
Server code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterArrayDeclaration("Skills", "'asa'");
Page.ClientScript.RegisterArrayDeclaration("Skills", "'bell'");
Page.ClientScript.RegisterArrayDeclaration("Skills", "'C'");
Page.ClientScript.RegisterArrayDeclaration("Skills", "'C++'");
}
}
Client side:
function showLocation()
{
var address = "izmit";
var address2 = "ağrı";
geocoder.getLocations(Skills[0], addAddressToMap);
}
Skills [0]の代わりに「asa」を使用すると、場所とマークが表示されますが、Skills[0]では機能しません。そして、私が探していたものであったあなたの答えに感謝します。
var MyValue =Skills[0];を試しても 次に、Skills[0]の代わりにMyValueを使用します。それでも機能しません