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

APIs Google Discussion :

Déterminer si une coordonnée GPS se situe dans un polygone [Google Maps]


Sujet :

APIs Google

  1. #1
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2011
    Messages
    192
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Transports

    Informations forums :
    Inscription : Février 2011
    Messages : 192
    Points : 107
    Points
    107
    Par défaut Déterminer si une coordonnée GPS se situe dans un polygone
    Bonjour, j'ai une petite question qui me bloque, je sais que c'est possible via des fonctions mathematiques, mais c'est vraiment coton je trouve et je suppose que googlemap l'a fait donc si quelqu'un sait comment cela marche..ça m'enleverait une bonne épine du pied ! (le seul lien valable étant mort... )

    en disposant d'un polygone et de ses coordonnées GPS, est il possible via une méthode de l'API, de déterminer si une coordonnées GPS quelconque est à l’intérieur ou à l’extérieur du polygone ?

    Merci d'avance

  2. #2
    Membre éclairé Avatar de EIN-LESER
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2008
    Messages
    703
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2008
    Messages : 703
    Points : 778
    Points
    778
    Par défaut
    Je crois que tu a fait peur a tout le monde sur ce coup la

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2011
    Messages
    192
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Transports

    Informations forums :
    Inscription : Février 2011
    Messages : 192
    Points : 107
    Points
    107
    Par défaut
    ha... mince alors !
    c'est vrai que ça pue les maths... mais je crois que ça serait la solution la plus simple pour ce que je veux faire...

    je cherche je cherche ! ça va être marrant !

    je poste si je trouve une solution >_<'

  4. #4
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2011
    Messages
    192
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Transports

    Informations forums :
    Inscription : Février 2011
    Messages : 192
    Points : 107
    Points
    107
    Par défaut
    bwwwjaaaaa !

    Je croyais devoir chercher tout seul,
    heureusement est arrivé google,
    un petit bout de code je recherchais,
    et non pas tout mon projet.

    on y trouve des fonctions pré-programmées,
    qui me font gagner une demi journée,
    merci à vous la silicon valley,
    pour tout le travail que vous m'évitez !


    le lien :
    http://code.google.com/p/google-maps.../source/browse

    le code :

    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
     
     
    		if (!google.maps.Polygon.prototype.getBounds) {
    		  google.maps.Polygon.prototype.getBounds = function(latLng) {
    		    var bounds = new google.maps.LatLngBounds();
    		    var paths = this.getPaths();
    		    var path;
     
    		    for (var p = 0; p < paths.getLength(); p++) {
    		      path = paths.getAt(p);
    		      for (var i = 0; i < path.getLength(); i++) {
    		        bounds.extend(path.getAt(i));
    		      }
    		    }
    		    return bounds;
    		  }
    		}
     
     
    		// Polygon containsLatLng - method to determine if a latLng is within a polygon
    		google.maps.Polygon.prototype.containsLatLng = function(latLng) {
    		  // Exclude points outside of bounds as there is no way they are in the poly
    		  var bounds = this.getBounds();
     
    		  if(bounds != null && !bounds.contains(latLng)) {
    		    return false;
    		  }
     
    		  // Raycast point in polygon method
    		  var inPoly = false;
     
    		  var numPaths = this.getPaths().getLength();
    		  for(var p = 0; p < numPaths; p++) {
    		    var path = this.getPaths().getAt(p);
    		    var numPoints = path.getLength();
    		    var j = numPoints-1;
     
    		    for(var i=0; i < numPoints; i++) {
    		      var vertex1 = path.getAt(i);
    		      var vertex2 = path.getAt(j);
     
    		      if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
    		        if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
    		          inPoly = !inPoly;
    		        }
    		      }
     
    		      j = i;
    		    }
    		  }
     
    		  return inPoly;
    		}
     
    	}

  5. #5
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 075
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 075
    Points : 44 679
    Points
    44 679

  6. #6
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2011
    Messages
    192
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Transports

    Informations forums :
    Inscription : Février 2011
    Messages : 192
    Points : 107
    Points
    107
    Par défaut
    effectivement, ça se ressemble pas mal !

    et pourtant javais déjà cherché sur le forum, sans succès...

    merci quand même ! c'est toujours bon à prendre !

  7. #7
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 075
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 075
    Points : 44 679
    Points
    44 679
    Par défaut
    effectivement, ça se ressemble pas mal !
    on part tous du même algo alors c'est un normal...

    et pourtant javais déjà cherché sur le forum, sans succès...
    c'est dans contribuez, il est vrai qu'il faut avoir le réflexe...

  8. #8
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 29
    Points : 25
    Points
    25
    Par défaut
    Et toujours d'actualité.
    Merci
    Meg

  9. #9
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 075
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 075
    Points : 44 679
    Points
    44 679
    Par défaut
    Et toujours d'actualité.
    NON depuis l'API à ajouter une méthode bien pratique containsLocation() que l'on trouve dans la Geometry Library

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 23/11/2012, 16h20
  2. Ajouter une distance à une coordonnée GPS
    Par jmnicolas dans le forum SIG : Système d'information Géographique
    Réponses: 1
    Dernier message: 06/03/2011, 22h54
  3. Réponses: 1
    Dernier message: 24/09/2008, 09h23
  4. Réponses: 14
    Dernier message: 11/08/2008, 22h28
  5. Réponses: 11
    Dernier message: 05/11/2007, 14h38

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