[英]how to add locations(markers) on a google map from database..?
我正在創建Google地圖,以顯示印度各地品牌的商店位置。
我已經將完整的地址以及經度和緯度存儲在我的SQL Server數據庫中...
在這里,我能夠從數據庫中獲取地址並顯示在我的網頁中,但我堅持使用,將地址映射到Google地圖上...
在這里,我保留了一個文本框,以便用戶輸入他的州/城市/任何位置名稱,然后單擊搜索按鈕,然后我必須用標記在地圖上標記相應的商店位置。
這是我的谷歌地圖代碼...
<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 ali shaik
乍一看,您的代碼似乎還不錯。 但是這是我的代碼,對我來說效果很好,可能會對您有所幫助。
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
});
古拉帕蘭·吉里塔蘭..
正如我在問題中告訴我的那樣,我想在印度各地查找商店。&疼痛的詳細信息將存儲在數據庫中。.現在,我能夠獲取商店的詳細信息並通過您的代碼在地圖上標記它們的位置。如果您在搜索框中提供了個人識別碼,它會檢索相應的商店詳細信息。
現在,按照我的代碼,在我對您的博客文章的回復中,我只能在文本框中輸入字符串值。在這里,我還需要將其實現為數字值(密碼),
這是我的更新面板和計時器click事件的代碼。
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語句中,我還需要輸入密碼。
任何幫助將是感激的..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.