2015-07-03 250 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>