2015-07-03 153 views
-1

我想创建一个简单的Windows窗体C#应用程序,显示一个谷歌地图与Lat Long列表中的多个标记。C#谷歌地图API多个标记

我的应用程序可以在其中包含一个Web浏览器容器。

是否有任何谷歌API?

+0

http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple -marker-example – user1666620

+0

这是为JS,我需要它为C#应用程序。 – Yogevnn

+0

你打算从浏览器或Windows窗体与Google地图进行交互吗? – user1666620

回答

2

我使用谷歌DLL来自动计算用在掘金控制台下面的代码路径:

PM> Install-Package GoogleMapsApi 

不知道是否会竭诚为您服务,但它的谷歌地图上的所有功能,只需知道如何使用。使用谷歌文档了解如何使用得好:https://developers.google.com/maps/

编辑1: 我用这个查询返回的veriable路线的所有可能的途径。

命名空间:

using GoogleMapsApi; 
using GoogleMapsApi.Entities.Directions.Request; 

var request = new DirectionsRequest 
{ 
     Origin = employeeAdress, 
     Destination = companyAdress, 
     TravelMode = TravelMode.Transit, 
     Alternatives = true, 
     ApiKey = key, 
     DepartureTime = DateTime.Now 
}; 
var routes = GoogleMaps.Directions.Query(request); 

但使用的是免费的关键在于谷歌给你,你每天只有2500个请求。

+0

你有在C#中使用它的例子吗? – Yogevnn

0

这里是与web浏览器来使用联为一个HTML页面的一些代码:

<html> 
<head> 
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
<title>GoogleMap</title> 
<style type="text/css"> v\:* { behavior:url(#default#VML); } </style> 
<script src="http://maps.google.com/maps/api/js?key=xxxxxxxxxxxxxx&sensor=false" type="text/javascript"></script> 
<script type="text/javascript"> 

    //======== Local Google API data =========================================================== 
    var map       = null; 
    var overlayvew     = null; 
    var geocoder      = null; 
    // ======== Local controls ====================================================== 
    var body_info_label    = null ; 
    var body_map      = null ; 


    //======== Local functions and Events ============================================ 
    function load() 
    { 
    body_info_label = document.getElementById("body_info_label"); 
    body_map  = document.getElementById("body_map")  ; 
    MapLoad(900,700,"H") ; 
    } 

    function MapLoad(Width,Height,MapType) 
    { 
    try 
    { 
     ToGM_SetMapSize(Width,Height) ; 
     var mapOptions = 
     { 
      center: new google.maps.LatLng(-25.363882, 131.044922), 
      zoom: 4, 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 
      // Add controls 
      mapTypeControl: false, scaleControl: true, streetViewControl:false, 
      overviewMapControl: false, overviewMapControlOptions: { opened: true } 
     }; 
     map = new google.maps.Map(body_map,mapOptions); 
    } 
    catch (ex){ window.external.FromGM_Uninitialized() ; } 
    if (map != null) 
    { 
     geocoder = new google.maps.Geocoder(); 
     ToGM_SetMapCenter(50.0,15.0,4); // Center and Zoom to Europe 
     ToGM_SetZoomControl (true ) ; // Create and Display zoom 
     ToGM_SetMapType  (MapType) ; // Display according to map Type 
     ToGM_SetScaleControl(true ) ; // Create and Display scale 
     overlayview = new google.maps.OverlayView(); 
     overlayview.draw = function() {}; 
     overlayview.setMap(map); 
     // call to a C# procedure to indicate end of init 
     // window.external.FromGM_Initialized() ; 
    } 
    } 



    //======== Some functions that may be called from C# by .Net WebBrowser ================================ 

    function ToGM_SetMapSize(Width,Height) 
    { 
    if (body_info_label!=null) Height=Height-15 ; 
    body_map.style.width =Width +"px" ; 
    body_map.style.height=Height+"px" ; 
    if (map!=null) google.maps.event.trigger(map, 'resize'); 
    } 

    function ToGM_SetMapCenter(Lat,Lon,Zoom) 
    { if (map!=null) { 
    if (Zoom==null) Zoom = map.getZoom() ; 
    var Center ; 
    if (Lat==null) Center = map.getCenter() ; 
    else Center = new google.maps.LatLng(Lat,Lon); 
    map.setCenter(Center) ; 
    map.setZoom(Zoom); 
    }} 

    function ToGM_SetZoomControl(On) 
    { 
    if (map!=null) map.setOptions({zoomControl:On}) ; 
    } 

    function ToGM_SetScaleControl(On) 
    {  
    if (map!=null) map.setOptions({scaleControl:On }) ; 
    } 

    function ToGM_SetMapType(MapType) // String MapType = "N"/"S"/"H"/"P" 
    {if (map!=null) { 
    if (MapType=="N") map.setMapTypeId(google.maps.MapTypeId.ROADMAP ); 
    if (MapType=="S") map.setMapTypeId(google.maps.MapTypeId.SATELLITE ); 
    if (MapType=="H") map.setMapTypeId(google.maps.MapTypeId.HYBRID ); 
    if (MapType=="P") map.setMapTypeId(google.maps.MapTypeId.TERRAIN ); 
    }} 

</script> 
</head> 

<body 
    onload="load()" onunload="unload()"> 
    <div id="body_map" style="width: 1000px; height: 600px"></div> 
</body> 
</html>