IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

code c# pour piloter google map


Sujet :

C#

  1. #1
    Candidat au Club
    Femme Profil pro
    Inscrit en
    Mai 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mai 2012
    Messages : 5
    Points : 4
    Points
    4
    Par défaut code c# pour piloter google map
    Bonsoir à tous ,
    j'ai une application qui consiste à créer une page html qui affiche la partie souhaité de google maps selon les coordonnées exécuté et par la suite de piloter cette mappe en utilisant le c#
    j'ai besoin du code qui me permet de placer un marqueur(qui peut être des petits carreaux) dans des lieux spécifiques et en cliquant sur ce marqueur une interface contenant les caractéristiques de ces endroits s'affichera
    j'attends votre réponse
    Merci

  2. #2
    Membre confirmé

    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Novembre 2011
    Messages
    244
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 46
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2011
    Messages : 244
    Points : 574
    Points
    574
    Par défaut
    Hello,
    En C# sur une page HTML ? Je comprends pas trop l'architecture de ton appli...
    C'est du client léger ?
    Merci de nous donner un peu plus de détails si tu veux de l'aide.

  3. #3
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Voici ce que tu peux trouver dans la page HTML que tu vas définir et charger dans ton WebBrowser :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    <html>
    <head><title>GoogleMap</title>
    <style type="text/css"> v\:* { behavior:url(#default#VML); } </style>
    <script src="http://maps.google.com/maps?file=api&v=2" type="text/javascript"></script>
    <script type="text/javascript">
     
      //======== Local Google API data ===========================================================
      var map                           = null;
      var geocoder                      = null;  
      var ScaleControl                  = null ;
      var ZoomControl                   = 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 unload() 
      {
        if (map != null) GUnload() ;
      }
     
      function MapLoad(Width,Height,MapType) 
      {
        ToGM_SetMapSize(Width,Height) ;
        try{ map = new GMap2(body_map);} catch (ex){ window.external.FromGM_Uninitialized() ; }
        if (map != null)
        { 
          geocoder = new GClientGeocoder();  
          ToGM_SetMapCenter(50.0,15.0,4); // Center and Zoom to Europe 
          new GKeyboardHandler(map);//flèches clavier activées
          ToGM_SetZoomControl (true   ) ; // Create and Display zoom
          ToGM_SetMapType     (MapType) ; // Display according to map Type
          ToGM_SetScaleControl(true   ) ; // Create and Display scale
          // map.addControl(new GOverviewMapControl());// Display mini-map
          // Initialize Events listeners
          GEvent.addListener(map,'click',OnMapClick) ;
          window.external.FromGM_Initialized() ;
         }
      }
     
     
      //======== Events communicating with .Net WebBrowser =============================
      function OnMapClick(overlay,point) 
      {
        if (point) window.external.FromGM_MapClick(point.x,point.y) ;
      }    
     
     
    //======== Functions called by .Net WebBrowser ================================
     
      function ToGM_SetMapCenterFromAddress(address,Zoom)
      { if (map!=null) {
        geocoder.getLatLng( address,function(Center) 
          { 
            if (!Center) { alert("Address not found: "+address); } 
            else 
            { 
              AddressCenter=Center ; 
              if (Zoom==null) Zoom = map.getZoom() ; 
              map.setCenter(Center,Zoom) ; 
            }
          }
        ) ;
      }}
     
      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 GLatLng(Lat,Lon) ;
        map.setCenter(Center,Zoom) ;
        // alert('Map center'+'(lat=' + Center.y + ' lon=' + Center.x + ') Zoom='+Zoom) ;
      }}
     
      function ToGM_GetMapCenter()
      {if (map!=null) { 
        var Center = map.getCenter() ;
        return Center.y+";"+Center.x ;
      }}
     
      function ToGM_GetScale()
      {
        if (map!=null) return  ""+map.getZoom() ;
        else return "" ;
      }
     
      function ToGM_SetZoomControl(On)
      {if (map!=null) {
        if (On)
        {
          if (ZoomControl==null) ZoomControl=new GLargeMapControl() ;
          map.addControl(ZoomControl); 
        }
        if (ZoomControl!=null && !On) map.removeControl(ZoomControl); 
      }}
     
      function ToGM_SetScaleControl(On)
      {if (map!=null) {
        if (On)
        {
          if (ScaleControl==null) ScaleControl=new GScaleControl() ;
          map.addControl(ScaleControl); 
        }
        if (ScaleControl!=null && !On) map.removeControl(ScaleControl); 
      }}
     
      function ToGM_SetMapType(MapType) // String MapType = "N"/"S"/"H"/"P"
      {if (map!=null) {
        if (MapType=="N") map.setMapType(G_NORMAL_MAP   ); 
        if (MapType=="S") map.setMapType(G_SATELLITE_MAP); 
        if (MapType=="H") map.setMapType(G_HYBRID_MAP   ); 
        if (MapType=="P") map.setMapType(G_PHYSICAL_MAP );
      }}
     
      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) map.checkResize() ;
      }
     
    </script>
    </head>
     
    <body 
      onload="load()" onunload="unload()">
      <div id="body_map" style="width: 1000px; height: 600px"></div>
    </body>
    </html>

  4. #4
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Et voici des bouts de code C# pour gèrer la form dans laquelle tu mets le WebBrowse. Comme j'ai élagué des lignes, le code suivant est juste fourni à titre indicatif. :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    using System;
    using System.Collections ;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace SxCSWFLib
    {
      [System.Runtime.InteropServices.ComVisible(true)]
      public partial class MyGoogleMapForm : Form // Needs be be "public" to communicate with JavaScript
      {
        private  float           InitialMapScale        = 4 ;
                                   
        public SxGoogleMapForm()
        {
          InitializeComponent();
          GM_WebBrowser.ObjectForScripting = this ;
        }
    
     
        // -------------------------- GoogleMap exchanges  -------------------------------------------------------------
        //
    
        public void FromGM_MapClick(float Lat, float Lon)
        {
          MessageBox.Show("Coord : "+Lat.ToString()+" / "+(-Lon).ToString());
        }
    
    
        private void ToGM_SetScaleControl(bool On) 
        {
          object [] BrowserArgs = { On } ;
          GM_WebBrowser.Document.InvokeScript("ToGM_SetScaleControl",BrowserArgs) ;
        }
    
        private void ToGM_SetZoomControl(bool On) 
        {
          object [] BrowserArgs = { On } ;
          GM_WebBrowser.Document.InvokeScript("ToGM_SetZoomControl",BrowserArgs) ;
        }
    
        private void ToGM_SetMapSize(int Width,int Height)
         {
            object [] BrowserArgs = { Width, Height } ;
            GM_WebBrowser.Document.InvokeScript("ToGM_SetMapSize",BrowserArgs) ;
         }
    
        private void ToGM_SetMapType(string MapType)
        {
          object [] BrowserArgs = { MapType[0]+"" } ;
          GM_WebBrowser.Document.InvokeScript("ToGM_SetMapType",BrowserArgs) ;
        }
    
        private string ToGM_GetMapCenter()
        { // keep center if MapCenter is undefined, keep Scale if Mapscale=0
          string Result="" ;
          object [] BrowserArgs = { } ;
          string s=(string)GM_WebBrowser.Document.InvokeScript("ToGM_GetMapCenter",BrowserArgs) ;
          if (s!=null) Result=s.Replace(".",SxStrings.NumberDecimalSeparator());
          return Result ;
        }
    
        private float ToGM_GetScale()
        { // keep center if MapCenter is undefined, keep Scale if Mapscale=0
          float Result ;
          object [] BrowserArgs = { } ;
          string s=GoogleMapActive?(string)GM_WebBrowser.Document.InvokeScript("ToGM_GetScale",BrowserArgs):"" ;
          if (!float.TryParse(s.Replace(',','.'),out Result)) Result=NmPerPixelToGoogleScale(InitialMapScale) ;
          return Result ;
        }
    
        private void ToGM_SetMapCenter(float LatInDeg,float LonInDeg, float MapScale)
        { // keep center if MapCenter is undefined, keep Scale if Mapscale=0
          object [] BrowserArgs = { LatInDegl, LonInDeg, MapScale>0?(object)MapScale:null } ;
          GM_WebBrowser.Document.InvokeScript("ToGM_SetMapCenter",BrowserArgs) ;
        }
    
        private void ToGM_SetMapCenterFromAddress(string Address,float Zoom)
        { 
          object [] BrowserArgs = { Address, Zoom } ;
          GM_WebBrowser.Document.InvokeScript("ToGM_SetMapCenterFromAddress",BrowserArgs) ;
        }
    
    
        // -------------------------- Tools  -------------------------------------------------------------
        //
        
        private float NmPerPixelToGoogleScale(float NmPerPixel) 
        {
          float Result ; 
          if (NmPerPixel<=0) Result=-1 ;
          else 
          {
            Result=4 ;
            NmPerPixel=NmPerPixel/2.5f ; // 4 auparavant
            while (NmPerPixel<1) { NmPerPixel=NmPerPixel*2 ; Result++ ; }
          }
          return Result ;
        }
    
     } // GoogleForm
    }

  5. #5
    Candidat au Club
    Femme Profil pro
    Inscrit en
    Mai 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mai 2012
    Messages : 5
    Points : 4
    Points
    4
    Par défaut
    @ plume 13
    Bonjour ,
    j'explique mieux l'application pour vous :
    j'ai créer une page html qui me permet d'afficher une mappe bien précise
    maintenant je veux que cette mappe sera afficher sur une interface (j'utilise Microsoft visual c# 2010)
    après çà ,je dois dessiner des triangle sur la mappe dans des endroits bien précis selon des coordonnées spécifique pour chaque endroit
    et par la suite avec un clik sur l'un de ces triangle une autre interface s'affichera qui contient les caractéristiques de ces milieux
    j'ai besoin du code c# qui me permet d'extraire la page HTML et de placer ces triangle
    Merci pour votre aide

  6. #6
    Candidat au Club
    Femme Profil pro
    Inscrit en
    Mai 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mai 2012
    Messages : 5
    Points : 4
    Points
    4
    Par défaut
    Bonjour Graffito
    j'ai exécuter votre code html et votre code c# mais ça ne marche pas
    c'est la première fois que j'utilise le c#

    c'est le code html utilisé de ma part :
    <html>
    <head>
    <title>Ma Page de Google Maps</title>
    <style type="text/css"> v\:* { behavior:url(#default#VML); } </style>
    <div id="map" style="width: 1000px; height: 600px"></div>
    <script src="http://maps.google.com/maps?file=api&v=2"
    type="text/javascript"></script>
    <script type="text/javascript">
    var map = null;
    function load() {
    try{
    map = new GMap2(document.getElementById("map"));
    new GKeyboardHandler(map);
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.addControl(new GOverviewMapControl());
    map.addControl(new GScaleControl());
    map.setMapType(G_NORMAL_MAP);
    var marker = new GMarker(new GLatLng(36.79426, 10.18218));

    map.addOverlay(marker);

    }



    catch (ex){alert("vous devez etre connecte a l'internet...");}
    if (map!= null){
    //Centrer la carte sur "Tunis" : zoom = 15
    map.setCenter(new GLatLng(36.79426, 10.18218) , 15);
    }
    }
    </script>
    </head>
    <body onload="load()" onunload="GUnload()">
    </body>

Discussions similaires

  1. Réponses: 6
    Dernier message: 04/10/2014, 15h26
  2. [Google Code] SVG inline pour firefox comme Google Maps
    Par moumoune65 dans le forum APIs Google
    Réponses: 2
    Dernier message: 01/07/2008, 17h07
  3. Code pour Google Map
    Par BFH dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 18/09/2007, 09h56
  4. [google map] code n'affiche pas les marqueurs voulus
    Par arnogef dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 08/03/2007, 11h19
  5. Google Map API --> Javascript et code behind C#
    Par bridel dans le forum ASP.NET
    Réponses: 2
    Dernier message: 22/01/2007, 21h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo