0

I want to create a simple windows form C# app that shows a google map with multiple markers from a list of Lat Long.

My app can include a web browser container in it.

Is there any google api for that?

Yogevnn
  • 1,430
  • 2
  • 18
  • 37
  • http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple-marker-example – user1666620 Jul 03 '15 at 14:27
  • that is for JS, i need it to be for c# app. – Yogevnn Jul 03 '15 at 14:30
  • do you intend to interact with the google maps from a browser or a windows form? – user1666620 Jul 03 '15 at 14:34
  • Window form, but i can add a web browser to it – Yogevnn Jul 03 '15 at 14:36
  • http://stackoverflow.com/questions/16274508/how-to-call-google-geocode-service-from-c-sharp-code – user1666620 Jul 03 '15 at 14:36
  • 2
    First create a local HTML page addressing the GoogleMap API. Then, load it in the browser. You will be able to call JavaScript from C# and C# from javascript. Refer to [that discussion](http://stackoverflow.com/questions/30926877/rewrite-part-of-javascript-with-c-sharp/30927408#30927408) – Graffito Jul 03 '15 at 14:50
  • If you are googling to find javascript code using the GoogleMap API, avoid old pages, because code produced some years ago relate to API V2 now replaced by API V3 (these 2 APIs aren't compatible). – Graffito Jul 03 '15 at 16:42

2 Answers2

2

I use a google dll to calculate routes automatically using in the Nugget Console the following code:

PM> Install-Package GoogleMapsApi

Not sure if it will serve you, but it has all the features of Google Maps on it, just know how to use. Use the google documentation to learn how to use it well: https://developers.google.com/maps/

Edit 1: I use this query that return all possible routes in the veriable routes.

Namespaces:

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

But using a free key that google gives to you, you have only 2500 requests per day.

Isabella
  • 33
  • 5
0

Here is some code for an HTML page to be used inconjunction with WebBrowser:

<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>
Graffito
  • 1,658
  • 1
  • 11
  • 10