`
gstarwd
  • 浏览: 1488378 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

[C#实战]Google Map开发实战参考

    博客分类:
  • .NET
阅读更多

[C# 实战]Google Map开发实战参考 

<script type="text/javascript"> document.body.oncopy = function() { if (window.clipboardData) { setTimeout(function() { var text = clipboardData.getData(&quot;text&quot;); if (text &amp;&amp; text.length &gt; 300) { text = text + &quot;\r\n\n本文来自CSDN博客,转载请标明出处:&quot; + location.href; clipboardData.setData(&quot;text&quot;, text); } }, 100); } } </script><script type="text/javascript"> function StorePage() { d = document; t = d.selection ? (d.selection.type != 'None' ? d.selection.createRange().text : '') : (d.getSelection ? d.getSelection() : ''); void (keyit = window.open('http://www.365key.com/storeit.aspx?t=' + escape(d.title) + '&amp;u=' + escape(d.location.href) + '&amp;c=' + escape(t), 'keyit', 'scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes')); keyit.focus(); }</script>
using  System;
using  System.Data;
using  System.Configuration;
using  System.Web;
using  System.Web.Security;
using  System.Text;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

/**/ ///   <summary>
///  Summary description for GoogleMapCommon
///   </summary>

public   class  GoogleMapCommon
... {
    Page mPageHandel 
=   null ;   
    
string  mMapDivName  =   string .Empty;
    GoogleMapPoint mCenterPoint;
    
string  mMapHandleName;
    
int  mMapZoom;
    
private   readonly   static   string  mGoogleMapURL  =  ConfigurationManager.AppSettings[ " GoogleMapURL " ];
    
/**/ ///   <summary>
    
///  Show Google Map
    
///   </summary>
    
///   <param name="pageHandel"> page handle </param>
    
///   <param name="mapHandleName"> Map Handle Name. </param>
    
///   <param name="mapDivName"> Div where Shows map </param>
    
///   <param name="centerPoint"> center point </param>
    
///   <param name="zoom"> map zoom 1 to 19 </param>

     public  GoogleMapCommon(Page pageHandel,  string  mapHandleName,  string  mapDivName, GoogleMapPoint centerPoint,  int  mapZoom)
    
... {
        mPageHandel 
=  pageHandel;
        mMapHandleName 
=  mapHandleName;
        mMapDivName 
=  mapDivName;
        mCenterPoint 
=  centerPoint;
        
if  (mapZoom  >   19   ||  mapZoom  <   1 )
        
... {
            mMapZoom 
=   4 ;
        }

        
else
        
... {
            mMapZoom 
=  mapZoom;
        }

    }

    
/**/ ///   <summary>
    
///  Show Google mape
    
///   </summary>

     public   void  ShowMap()
    
... {
        ShowMap(
null );
    }

    
/**/ ///   <summary>
    
///   Show Google mape
    
///   </summary>
    
///   <param name="point"></param>

     public   void  ShowMap(GoogleMapPoint point)
    
... {
        GoogleMapPoint[] points 
= ... { point} ;
        ShowMap(points);
    }

    
/**/ ///   <summary>
    
///  Show Google mape
    
///   </summary>
    
///   <param name="points"></param>

     public   void  ShowMap(GoogleMapPoint[] points)
    
... {
        mPageHandel.ClientScript.RegisterClientScriptInclude(
" GoogleMaps " , mGoogleMapURL);
        StringBuilder js 
=   new  StringBuilder( " var  "   +  mMapHandleName  +   "  = null;  " );
        js.AppendLine(
" function load() " );
        js.AppendLine(
" " );
        js.AppendLine(
"      if (GBrowserIsCompatible())  " );
        js.AppendLine(
"      { " );
        js.AppendLine(
"            "   +  mMapHandleName  +   "  = new GMap2(document.getElementById(" "   +  mMapDivName  +   " ")); " );
        js.AppendLine(
"       "   +  mMapHandleName  +   " .setCenter(new GLatLng( "   +  mCenterPoint.Latitude  +   " "   +  mCenterPoint.Longitude  +   " ), "   +  mMapZoom  +   " ); " );
        
if  (points  !=   null )
        
... {
            
for  ( int  i  =   0 ; i  <  points.Length; i ++ )
            
... {
                js.AppendLine(
"  var point "   +  i  +   "  = new GLatLng( "   +  points[i].Latitude  +   " "   +  points[i].Longitude  +   " ) " );
                js.AppendLine(
" var blueIcon = new GIcon(G_DEFAULT_ICON); " );
                js.AppendLine(
" blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png "; " );
                js.AppendLine(
" blueIcon.iconSize = new GSize(35,35); " );
                js.AppendLine(
" blueIcon.shadowSize=new GSize(60,35); " );
                js.AppendLine(
" markerOptions = { icon:blueIcon };  " ); 
                
if  (points[i].IsBuleIcon)    // Create a blue icon
                 ... {
                    js.AppendLine(
"  var marker "   +  i  +   "  = new GMarker(point "   +  i  +   " ,markerOptions); " );
                }

                
else
                
... {
                    js.AppendLine(
"  var marker "   +  i  +   "  = new GMarker(point "   +  i  +   " ); " );
                }

                
if  ( ! string .IsNullOrEmpty(points[i].PointClickHandle))
                
... {
                    
//  add event
                    js.AppendLine( " GEvent.addListener(marker "   +  i  +   " , "click", function(){  "   +  mMapHandleName  +   " .openInfoWindowHtml(point "   +  i  +   " "   +  points[i].PointClickHandle  +   " )}); " );
                }

                js.AppendLine(mMapHandleName 
+   " .addOverlay(marker "   +  i  +   " ); " );
            }

        }

        js.AppendLine(
"      } " );
        js.AppendLine(
" } " );  // create function finsh
        js.AppendLine( " load(); " );    //  call the load function.
        mPageHandel.ClientScript.RegisterStartupScript(mPageHandel.GetType(),  " Start " , js.ToString(), true );
    }

    
/**/ ///   <summary>
    
///  Google Map Point
    
///   </summary>

     public   struct  GoogleMapPoint
    
... {
        
public  GoogleMapPoint( double  longitude,  double  latitude)
        
... {
            Longitude 
=  longitude;
            Latitude 
=  latitude;
            PointClickHandle 
=   string .Empty;
            IsBuleIcon 
=   false ;
        }

        
public  GoogleMapPoint( double  longitude,  double  latitude,  string  pointClickHandle,  bool  isBuleIcon)
        
... {
            Longitude 
=  longitude;
            Latitude 
=  latitude;
            PointClickHandle 
=  pointClickHandle;
            IsBuleIcon 
=  isBuleIcon;
        }

        
public   double  Longitude;
        
public   double  Latitude;
        
public   string  PointClickHandle;
        
public   bool  IsBuleIcon;
    }

}

  该类封装了Google Maps API的一些最基本功能,供大家参考。 详情请参考: http://code.google.com/apis/maps/documentation/index.html
分享到:
评论

相关推荐

    C#开发实战1200例(第2卷) Part1

    《C#开发实战1200例(第2卷)》非常适合c#项目开发人员、c#初学者及编程爱好者使用,同时也可作为培训机构、大中专院校老师和学生的实践参考用书。 《C#开发实战1200例(第2卷)》以开发人员在项目开发中经常遇到的...

    C#开发实战1200例源代码.zip

    C#开发实战1200例源代码.zip

    C#开发实战1200例.(第Ⅰ卷) pdf

    《C#开发实战1200例(第1卷)》以开发人员在项目开发中经常遇到的问题和必须掌握的技术为中心,介绍了应用C#进行程序开发各个方面的知识和技巧,主要包括C#编程基础、Windows窗体、控件应用、文件操作、C#与Office...

    C#上位机实战开发指南

    基于C#的上位机开发实战指南,介绍了上位机软件开发过程中重点内容以及注意事项。

    C#-googlemap

    C#下googlemap的使用实例

    C#开发GooGleMap

    C#开发的GooGleMap

    C#开发实战1200例源码

    C#开发实战1200例(第Ⅰ卷) 这本书籍附带的光盘源码,很有参考价值 二、菜单功能 内附一千多winform开发的教学实例,非常适合初学者用来学习,有兴趣的欢迎下载 三、注意事项 1、开发环境为Visual Studio 2010,...

    C#开发实战1200例+第1卷.part7

     《C#开发实战1200例(第1卷)(附光盘)》适合c#的初学者,如高校学生、求职人员作为练习、速查、学习使用,也适合c#程序员参考、查阅。 目录 第1篇 c#编程基础篇 第1章 c#开发环境的使用 第2章 c#语言...

    20个C#项目实战开发及项目源码(全部源码)

    20个C#项目实战开发及项目源码(全部源码),20个C#项目实战开发及项目源码(全部源码),亲测可用

    C#开发实战1200例(第2卷)源代码_C#_c#编程1200例_

    C#开发实战1200例(第2卷)源代码.rar

    Visual C#.NET项目实战开发从入门到精通 Part 2

    本书是一本讲解如何通过Visual C#.NET开发应用软件的书籍,它以5个实际项目为依托,全面而系统地再现了项目开发的实际过程,具有很大的实用价值和参考意义。  全书首先介绍SQL Server 2000基础知识、ADO.NET基础...

    《C#开发Android应用实战 使用Mono for Android和.NET C#》

    C# Android 《C#开发Android应用实战 使用Mono for Android和.NET C#》

    C#与mapobject开发地理信息系统

    C#与mapobject开发地理信息系统.pdf 一篇论文,可以参考下

    明日科技C#开发入门及项目实战

    内附1-19章的实战程序。 目录 第1章 c#语言及其开发环境 实例001 根据需要创建所需解决方案 实例002 统一窗体中控件的字体设置 实例003 设置程序代码行号 实例004 通过“格式”菜单布局窗体 实例005 为项目添加dll...

    C#开发实战1200例(第Ⅱ卷)光盘

    C#开发实战1200例(第Ⅱ卷) 王小科,王军 清华大学出版社 ... 《C#开发实战1200例(第2卷)》非常适合c#项目开发人员、c#初学者及编程爱好者使用,同时也可作为培训机构、大中专院校老师和学生的实践参考用书。

    C#开发实战1200例

    C#开发实战1200例

    C#开发实战1200例(第Ⅰ卷) 第一部分.pdf

    《C#开发实战1200例》包括第I卷、第II卷共计1200个例子,本书是第I卷,共计600个例子。 本书以开发人员在项目开发中经常遇到的问题和必须掌握的技术为中心,介绍了应用C#进行程序开发各个方面的知识和技巧,主要包括...

    c#开发实战宝典1

    c#开发实战宝典分了三个部分。全部下载

Global site tag (gtag.js) - Google Analytics