2017-09-20 5 views
0

C#의 루프 내에서 JavaScript 함수를 호출합니다. 각 호출은 설명, 경도 및 위도를 함수에 보냅니다. 이 함수는지도 내에 개별 마커를 만듭니다. 루프에서 해당 정보가 전송되는 모든 마커가 표시됩니다. 내가보고있는 것은 보낸 마지막 항목의 표식입니다.Google지도에서 마커 만들기, 마지막 마커 만 표시

C# 코드

 protected void MapButton_Click(object sender, EventArgs e) 
    { 
     /////////////////////////////////////////////// 
     // Get all Games that are being played today // 
     // then send HomeTeam, AwayTeam and   // 
     // Coordinates to MapIt.      // 
     /////////////////////////////////////////////// 

     /////////////////////////////////////////////// 
     // Step 1: Call Stored Procedure that will // 
     //   return the TeamNames and   // 
     //   Coordinates where the games will // 
     //   be played today.     // 
     /////////////////////////////////////////////// 
     string strcon = WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; 
     using (SqlConnection conn = new SqlConnection(strcon)) 
     { 
      SqlCommand cmd = new SqlCommand("GameDayCoordinates", conn); 
      cmd.CommandType = CommandType.StoredProcedure; 
      conn.Open(); 
      DataTable MapItTbl = new DataTable(); 
      SqlDataAdapter da = new SqlDataAdapter(cmd); 
      da.Fill(MapItTbl); 
      /////////////////////////////////////////////// 
      // Step 2: Send each set of Teams and  // 
      //   Coordinates to MapIt. Within a // 
      //   loop.        // 
      // Send the Google Map Coordinates, and this // 
      // function will mark the places on Google // 
      // Maps via a JavaScript function.   // 
      /////////////////////////////////////////////// 

      int count = MapItTbl.Rows.Count; 
      string[] splitSeparator = new string[] { ", ",", "}; 
      LocObject[] LocationInfo = new LocObject[count]; 

      for (int i = 0; i < MapItTbl.Rows.Count; i++) 
      { 
       DataRow row = MapItTbl.Rows[i]; 
       string Coordinates = row["Coordinate"].ToString(); 
       if (Coordinates != "NULL") { 
        string[] strArr = Coordinates.Split(splitSeparator, StringSplitOptions.None); 
        ScriptManager.RegisterStartupScript((Page)this, base.GetType(), i + "GMaps" + DateTime.UtcNow, string.Format("GameMap('{0}','{1}','{2}','{3}');", row.ItemArray.GetValue(0).ToString(), strArr[0], strArr[1], i), true); 
       } 
      } 
     } 
    } 

표시하기 (단지 마지막 마커에 반대)

  function GameMap(description, lat, lng, index) { 

      var marker = new Array(); 
      var i; 
      var max = 100; 
      var myLatLng = { lat: 32.787407, lng: -82.269194 }; 
      var MapObj; 
      MapObj = document.getElementById('map1'); 

      var map1 = new google.maps.Map(MapObj, { 
       zoom: 7, 
       center: myLatLng, 
       mapTypeId: google.maps.MapTypeId.HYBRID 
      }); 

      var GameLatlng = new google.maps.LatLng(parseFloat(lat), parseFloat(lng)); 

      document.write(description); 
      document.write(index); 

      marker = new google.maps.Marker({ 
       position: GameLatlng, 
       title: description 
      }); 

      //for (i = 0; i < 8; i++) { 
      marker.setMap(map1); 
      //} 
     } 

가 어떻게 마커를 모두받을 수 있나요 호출 된 자바 스크립트 함수?

+1

'var에 마커 = 새 Array();',,, 다음'마커 = 새로운 google.maps.Marker ({'... 그래서, 배열로 사용되지 않습니다 표시, 왜 당신은 초기화 할 –

+0

마커가 유일하게 식별되기를 바라는 한 지점에서 배열로 사용하려고 시도했습니다 . – MDDeVane

+0

JavaScript 기능을 종료 한 후에 마커가 계속 표시되도록하는 방법이 있습니까? 마커가 생성되면 JavaScript 함수를 새로 호출 할 때 재정의됩니까? – MDDeVane

답변

0

"Good poing .... Thanks!"뒤에 코멘트보기

<script type="text/javascript"> 

    var map; 
     function initMap() { 

      var myLatLng = { lat: 32.787407, lng: -83.269194 }; 

      map = new google.maps.Map(document.getElementById('map1'), { 
       zoom: 7, 
       center: myLatLng, 
       mapTypeId: google.maps.MapTypeId.HYBRID 
      }); 

      //var marker = new google.maps.Marker({ 
      // position: myLatLng, 
      // map: map 
      //}); 
     } 



     function GameMap(description, Lat, Lng) { 

      var GameLatlng = new google.maps.LatLng(Lat, Lng); 

      var marker = new google.maps.Marker({ 
       position: GameLatlng, 
       title: description, 
       map: map 
      }); 

      document.write(description); 
      document.write(" * "); 
      document.write(Lat); 
      document.write(" * "); 
      document.write(Lng); 
      document.write("<br>"); 
     } 

</script> 
관련 문제