Google (または bing) マップで場所を特定しようとしていますが、両方で特定できません。コード構造はどちらも似ています。Google マップの試みを紹介します。
目的: オブジェクトのリンク リストがあり、それぞれに緯度と経度が含まれており、そのすべてを特定する必要があります。
フル ASP: http://pastie.org/7752124 (リピーターは検索結果を表示するためのものです)
関連する(頭の中):
<script type="text/javascript">
var map = null;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(40.42, -98.737),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
//pushPin(25, 80);
}
function pushPin(lat, lon) {
alert(lat + " " + lon);
var myLatlng = new google.maps.LatLng(lat, lon);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "Hello World!"
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
Codebehind: ユーザーが検索ボタンをクリックするとアクティブになります:
protected void Button1_Click(object sender, EventArgs e)
{
List<Results> rlist = getResults(query);
String Locations = "";
foreach (Results res in rlist)
{
Page.ClientScript.RegisterStartupScript(
GetType(),
"MyKey",
"pushPin("+res.latitude+","+res.longitude+");",
true);
}
this.rptREsults.DataSource = rlist;
this.rptREsults.DataBind();
}
public class Results
{
public string filename { get; set; }
public string asciiname { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
}
結果は正しく、緯度と経度が含まれています。pushPin メソッドにアラートを入れると、アラート ボックスは 1 つだけ表示されますが、ピンポイントは作成されません。緯度と経度のリストを保存して特定するより良い方法はありますか?
pushPin メソッドは、別の JavaScript メソッドから呼び出すと機能します。