如何添加谷歌地图上的位置(标记)从数据库..? [英] how to add locations(markers) on a google map from database..?

查看:114
本文介绍了如何添加谷歌地图上的位置(标记)从数据库..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个谷歌地图,以显示一个品牌在印度各地的商店位置... ...

我已经存储了完整的地址,纬度&我的SQL服务器数据库中的经度...

这里我能够从数据库中获取地址并显示在我的网页中,但是我坚持使用,映射地址在谷歌地图上...



这里我保留了一个文本框,以便用户输入他的州/城市/任何位置名称,并单击搜索按钮,然后我有通过一个标记在地图上标记相应的商店位置。



这里是我的代码googgle map ...

 < script type =text / javascript> 
var infowindow = null;
函数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(地图,网站);
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,班加罗尔,卡纳塔克邦,印度,560038'],['TamilNadu',11.415418,78.662109,1,'TamilNadu,印度,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,
图标:new google.maps.MarkerImage(
'图片/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

解决方案Guruparan Giritharan ..



正如我在我的问题中所说的,我想在印度找到商店。&疼痛的细节将被存储在数据库中..
现在,我能够获得商店的详细信息&通过您的代码在地图上标出它们的位置..
早些时候,它对pincode工作正常,从某种意义上说,如果您在搜索框中提供pincode,它将检索相应的
商店详情..



现在,根据我的代码,在我的博客文章回复中,我只能在文本框中输入字符串值,在这里我需要实现它的数值(pincode )还有,

这里是我的代码更新面板和定时器点击事件。

  {
// Linq用于将表加载到代码中
DataClassesDataContext data = new DataClassesDataContext();

//从表格中选择全部
// List< addressmap> lst =(从data.addressmaps中选择你选择的u).ToList();
列表< addressmap> lst =(从u在data.addressmaps其中u.StoreLocation == TxtSearch.Text || u.StoreCity == TxtSearch.Text || u.StoreState == TxtSearch.Text || u.StoreCountry == TxtSearch.Text选择您).ToList();


//将表格内容添加到javascript数组中,以便新的位置将被加载
foreach(地址图项目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());



保护无效Timer1_Tick(对象发送者,EventArgs e)
{
//每10秒更新一次更新面板
UpdatePanel1.Update();
}

在select语句中,我还需要pincode ..



任何帮助都会感恩。


I am creating a google map in order to display store locations of a brand across india...

i have stored the complete address, with latitude & longitude in my SQL server database...

here I am able to get the address from database and display in my web page, but i am stuck with, mapping the address on google map...

here i have kept a text box so that the user enters his state/city/any location name, and clicks search button, then i have to mark the corresponding store location on the map by a marker..

here's my code for googgle map...

<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>

here, i have sites variable, so that i can map my locations on a map,

but here i need to map them from database...

any help will be appreciated...

thanks shameer ali shaik

解决方案

Guruparan Giritharan..

As i have told in my question, I want to locate stores across india.. & the sore details will be stored in database.. Now, i am able to get the store details & mark their location on map by your code.. earlier it is working fine for pincode, in the sense if you provide pincode in your searchbox, it will retrieve the corresponding store details..

Now, as per my code, in my reply for your blog post, i am able to enter only string values in the textbox., here i need to implement it for numeric values(pincode) also,

here's my code of update panel and timer click event..

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();
    }

here in the select statement, i need for pincode also..

any help will be thankful..

这篇关于如何添加谷歌地图上的位置(标记)从数据库..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆