2012-12-03 30 views
1

我爲了顯示印度各地的品牌專賣店位置創建一個谷歌地圖...如何在數據庫的谷歌地圖上添加位置(標記)..?

我已存儲的完整地址,在我的SQL Server數據庫中緯度經度& ......

這裏我能夠得到我的網頁數據庫,並顯示地址,但我堅持,映射在谷歌地圖的地址...

這裏讓用戶輸入自己的狀態,我一直一個文本框/城市/任何位置名稱,然後單擊搜索按鈕,然後我必須用標記在地圖上標記相應的商店位置。

,這裏是我的googgle地圖代碼...

<script type="text/javascript"> 
    var infowindow = null; 
    function initialize() { 
     //var centerMap = new google.maps.LatLng(13.040547,80.230805); 
     var centerMap = new google.maps.LatLng(12.264864, 77.937012); 
     var myOptions = { 
      zoom: 7, 
      center: centerMap, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     } 
     var map = new google.maps.Map(document.getElementById("map"), myOptions); 
     setMarkers(map, sites); 
     infowindow = new google.maps.InfoWindow({ }); 
    } 

    //var sites = '<%=TextBox1.Text%>' 
    //alert(sites); 
    //[ 
    //// ['Ambattur', 13.119438,80.148182, 4, 'Ambattur, Chennai, Tamil Nadu, India, 600031'],['Avadi', 13.124453,80.101662, 1, 'Avadi, Tamil Nadu, India, 600017'], ['Jayanagar', 12.928945,77.590599, 1, 'Jayanagar, Bangalore, Karnataka, India,  560041'],['Indira Nagar', 12.973697,77.641325, 1, 'Indira Nagar, Bangalore, Karnataka, India, 560038'],['TamilNadu',  11.415418,78.662109, 1, 'TamilNadu, India, 600017'] 
    //]; 

    function setMarkers(map, markers) { 
     for (var i = 0; i < markers.length; i++) { 
      var sites = markers[i]; 
      var siteLatLng = new google.maps.LatLng(sites[1], sites[2]); 
      var marker = new google.maps.Marker({ 
       position: siteLatLng, 
       map: map, 
       icon: new google.maps.MarkerImage(
       'Images/R.png ', 
       null, null, new google.maps.Point(0, 42)), 
       title: sites[0], 
       zIndex: sites[3], 
       html: sites[4] 
      }); 

      google.maps.event.addListener(marker, "click", function() { 
       infowindow.setContent(this.html); 
       infowindow.open(map, this); 
      }); 
     } 
    } 
</script> 

在這裏,我有變異位點,這樣我可以在地圖上繪製我的位置,

但在這裏,我需要從數據庫映射它們...

任何幫助將不勝感激......

感謝 shameer阿里shaik

回答

0

Guruparan Giritharan ..

正如我在我的問題告訴我要找到商店在印度各地.. &痠痛的詳細信息將被存儲在數據庫.. 現在,我能夠拿到店裏細節&由代碼標記他們在地圖上的位置.. 早些時候,它正在罰款的pin碼,在這個意義上,如果你在你的搜索框提供PIN碼,將獲取相應的 店詳細..

現在,根據我的代碼,在我的回覆您的博客文章中,我能夠在文本框中只輸入字符串值,在這裏我需要實現它的數值(pincode)也,

這是我的代碼更新面板和計時器單擊事件..

protected void UpdatePanel1_Load(object sender, EventArgs e) 
    { 
     //Linq is used to load the table to the code 
     DataClassesDataContext data = new DataClassesDataContext(); 

     //Select all from the table 
     //List<addressmap> lst = (from u in data.addressmaps select u).ToList(); 
     List<addressmap> lst = (from u in data.addressmaps where u.StoreLocation == TxtSearch.Text || u.StoreCity == TxtSearch.Text || u.StoreState == TxtSearch.Text || u.StoreCountry == TxtSearch.Text select u).ToList(); 


     //add the table contents to the javascript array so that new locations will be loaded 
     foreach (addressmap item in lst) 
     { 
      ScriptManager.RegisterArrayDeclaration(UpdatePanel1, "infoarray", "'" + item.StoreAddress.ToString() + "'"); 
      ScriptManager.RegisterArrayDeclaration(UpdatePanel1, "lonarray", item.StoreLongitude.ToString()); 
      ScriptManager.RegisterArrayDeclaration(UpdatePanel1, "latarray", item.StoreLatitude.ToString()); 
      ScriptManager.RegisterArrayDeclaration(UpdatePanel1, "bounce", item.StoreBounce.ToString()); 
     } 
    } 

    protected void Timer1_Tick(object sender, EventArgs e) 
    { 
     //update the update panel every 10 seconds 
     UpdatePanel1.Update(); 
    } 

在這裏的SELECT語句,我需要PIN碼也..

任何幫助會感激..

0

乍一看,你的代碼看起來沒問題。但這裏是我的代碼,對我來說工作得很好,可能對你有幫助。

myLatlng = new google.maps.LatLng(32.54681317351514,15.1171875);

map = new google.maps.Map(document.getElementById(「gmap」),{mapTypeId:google.maps.MapTypeId.ROADMAP,zoom:2,center:myLatlng});

/* loop which plot the markers on the map*/ 
// record[i] holds lat&lang in this format'32.54681317351514, 15.1171875' 

    var points=record[i].geo_location.split(','); 
    marker = new google.maps.Marker({ 
       position: new google.maps.LatLng(points[0],points[1]), 
       draggable: false, 
       map: map 
       }); 
相關問題