2017-08-29 3 views
-1

Ich habe einen freien Text, den ich in Koordinaten konvertieren muss, aber der Text Ziel zu Straßen und Straßen Injektionen.Get Straße Position von Text über Google Maps api

Das Problem ist, dass Google API Geocoding-Dienst die umliegenden Gebäude zurück, aber ich brauche die Straße selbst.

zum Beispiel: für US95 und Sonnenuntergang in Las Vegas Suche zurück

{ 
    "results" : [ 
     { 
     "address_components" : [ 
      { 
       "long_name" : "U.S. 95", 
       "short_name" : "US-95", 
       "types" : [ "route" ] 
      }, 
      { 
       "long_name" : "Whitney Ranch", 
       "short_name" : "Whitney Ranch", 
       "types" : [ "neighborhood", "political" ] 
      }, 
      { 
       "long_name" : "Henderson", 
       "short_name" : "Henderson", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Clark County", 
       "short_name" : "Clark County", 
       "types" : [ "administrative_area_level_2", "political" ] 
      }, 
      { 
       "long_name" : "Nevada", 
       "short_name" : "NV", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "United States", 
       "short_name" : "US", 
       "types" : [ "country", "political" ] 
      }, 
      { 
       "long_name" : "89014", 
       "short_name" : "89014", 
       "types" : [ "postal_code" ] 
      } 
     ], 
     "formatted_address" : "US-95 & W Sunset Rd, Henderson, NV 89014, USA", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : 36.0636796, 
        "lng" : -115.0334434 
       }, 
       "southwest" : { 
        "lat" : 36.0632289, 
        "lng" : -115.033988 
       } 
      }, 
      "location" : { 
       "lat" : 36.0635045, 
       "lng" : -115.0336492 
      }, 
      "location_type" : "GEOMETRIC_CENTER", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 36.0648032302915, 
        "lng" : -115.0323667197085 
       }, 
       "southwest" : { 
        "lat" : 36.0621052697085, 
        "lng" : -115.0350646802915 
       } 
      } 
     }, 
     "partial_match" : true, 
     "place_id" : "ChIJf0Azwu_QyIARci-cUiUBGMg", 
     "types" : [ "route" ] 
     }, 
     { 
     "address_components" : [ 
      { 
       "long_name" : "U.S. 95", 
       "short_name" : "US-95", 
       "types" : [ "route" ] 
      }, 
      { 
       "long_name" : "Henderson", 
       "short_name" : "Henderson", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Clark County", 
       "short_name" : "Clark County", 
       "types" : [ "administrative_area_level_2", "political" ] 
      }, 
      { 
       "long_name" : "Nevada", 
       "short_name" : "NV", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "United States", 
       "short_name" : "US", 
       "types" : [ "country", "political" ] 
      }, 
      { 
       "long_name" : "89011", 
       "short_name" : "89011", 
       "types" : [ "postal_code" ] 
      } 
     ], 
     "formatted_address" : "US-95 & W Sunset Rd, Henderson, NV 89011, USA", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : 36.0616173, 
        "lng" : -115.029007 
       }, 
       "southwest" : { 
        "lat" : 36.0591372, 
        "lng" : -115.0301591 
       } 
      }, 
      "location" : { 
       "lat" : 36.0603734, 
       "lng" : -115.0295973 
      }, 
      "location_type" : "GEOMETRIC_CENTER", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 36.0617262302915, 
        "lng" : -115.0282340697085 
       }, 
       "southwest" : { 
        "lat" : 36.0590282697085, 
        "lng" : -115.0309320302915 
       } 
      } 
     }, 
     "partial_match" : true, 
     "place_id" : "ChIJmZvnMeTQyIARi5giBwp9Ylc", 
     "types" : [ "route" ] 
     }, 
     { 
     "address_components" : [ 
      { 
       "long_name" : "U.S. 95", 
       "short_name" : "US-95", 
       "types" : [ "route" ] 
      }, 
      { 
       "long_name" : "Whitney Ranch", 
       "short_name" : "Whitney Ranch", 
       "types" : [ "neighborhood", "political" ] 
      }, 
      { 
       "long_name" : "Henderson", 
       "short_name" : "Henderson", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Clark County", 
       "short_name" : "Clark County", 
       "types" : [ "administrative_area_level_2", "political" ] 
      }, 
      { 
       "long_name" : "Nevada", 
       "short_name" : "NV", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "United States", 
       "short_name" : "US", 
       "types" : [ "country", "political" ] 
      }, 
      { 
       "long_name" : "89014", 
       "short_name" : "89014", 
       "types" : [ "postal_code" ] 
      } 
     ], 
     "formatted_address" : "US-95 & W Sunset Rd, Henderson, NV 89014, USA", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : 36.065207, 
        "lng" : -115.0334417 
       }, 
       "southwest" : { 
        "lat" : 36.0648819, 
        "lng" : -115.0334889 
       } 
      }, 
      "location" : { 
       "lat" : 36.065045, 
       "lng" : -115.0334589 
      }, 
      "location_type" : "GEOMETRIC_CENTER", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 36.06639343029149, 
        "lng" : -115.0321163197085 
       }, 
       "southwest" : { 
        "lat" : 36.0636954697085, 
        "lng" : -115.0348142802915 
       } 
      } 
     }, 
     "partial_match" : true, 
     "place_id" : "ChIJ5bnQNO7QyIAReqWyr22kKYc", 
     "types" : [ "route" ] 
     }, 
     { 
     "address_components" : [ 
      { 
       "long_name" : "U.S. 95", 
       "short_name" : "US-95", 
       "types" : [ "route" ] 
      }, 
      { 
       "long_name" : "Midway", 
       "short_name" : "Midway", 
       "types" : [ "neighborhood", "political" ] 
      }, 
      { 
       "long_name" : "Henderson", 
       "short_name" : "Henderson", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Clark County", 
       "short_name" : "Clark County", 
       "types" : [ "administrative_area_level_2", "political" ] 
      }, 
      { 
       "long_name" : "Nevada", 
       "short_name" : "NV", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "United States", 
       "short_name" : "US", 
       "types" : [ "country", "political" ] 
      }, 
      { 
       "long_name" : "89011", 
       "short_name" : "89011", 
       "types" : [ "postal_code" ] 
      } 
     ], 
     "formatted_address" : "US-95 & W Sunset Rd, Henderson, NV 89011, USA", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : 36.0631541, 
        "lng" : -115.0303368 
       }, 
       "southwest" : { 
        "lat" : 36.0628498, 
        "lng" : -115.0303404 
       } 
      }, 
      "location" : { 
       "lat" : 36.063002, 
       "lng" : -115.0303386 
      }, 
      "location_type" : "GEOMETRIC_CENTER", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 36.0643509302915, 
        "lng" : -115.0289896197085 
       }, 
       "southwest" : { 
        "lat" : 36.0616529697085, 
        "lng" : -115.0316875802915 
       } 
      } 
     }, 
     "partial_match" : true, 
     "place_id" : "ChIJAzrYiuXQyIARIZcbN66ts10", 
     "types" : [ "route" ] 
     } 
    ], 
    "status" : "OK" 
} 

aber die wirklichen Koordinaten ich brauche sind: 36,063761 -115,032024.

Irgendwelche Ratschläge, wie man die Straßenkoordinaten erhält?

+1

In Ihrem Beispiel hat der erste Eintrag den Typ "route", er baut nicht. Die Position ist im Geocoder-Tool zu sehen: https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D36.063505%252C-115.033649. Es sieht so aus, als ob dieses Beispiel wie erwartet funktioniert. – xomena

+0

Ja, aber die gewünschte Koordinate wird von den Ergebnissen ausgeschlossen –

Antwort

0

würde ich folgende Empfehlungen für die US-Straßen deuten darauf hin, dass die Formatierung Sie in

https://developers.google.com/maps/faq#geocoder_highways

also in Ihrem Fall der Suchbegriff sollte "& Sonnenuntergang, Las Vegas 95 US-" zu finden sein. Die entsprechende Anfrage (Anmerkung URL-codierte Suchtext)

https://maps.googleapis.com/maps/api/geocode/json?address=U.S.%2095%20%26%20sunset%2C%20las%20vegas&key=YOUR_API_KEY

Diese Anfrage gibt ein Ergebnis vom Typ Kreuzung sein wird, wie in meinem Screenshot

enter image description here

gezeigt können Sie auch diese sehen in Geocoder-Tool:

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3DU.S.%252095%2520%2526%2520sunset%252C%2520las%2520vegas

Ich hoffe, das hilft!

+0

Das ist großartig! Ich werde es überprüfen und Sie wissen lassen. BTW, eine Idee, wie man i215 & Far Hills Ave (auch Las Vegas) abfragt? Ich frage, weil in diesem Abschnitt i215 eine Adresse ist, so dass es komplizierter (i215 kann entweder eine Interstate Highway oder eine Landstraße "Bruce Woodbury Beltway" sein). –

+0

Habe gerade gemerkt, dass es nicht der gewünschte Ort ist. Ich wollte "W sunset Rd" und standardmäßig "Sunset Dr", was eine kleinere Straße ist. Gibt es eine Möglichkeit, Ergebnisse nach Straßentypen zu priorisieren? [Dies ist der Spot] (https://www.google.com/maps/place/US-95,+Henderson,+NV+89014/@36.0659837,-115.0346698,17z/data=!3m1!4b1!4m13! 1m7! 3m6! 1s0x80c8d0ee0715e219: 0x20d1f9d85a2151ac! 2sUS-95 +% 26 + Veteranen + Denkmal + Highway +% 26 + US-93, + Henderson, + NV + 89014! 3b1! 8m2! 3d36.0669328! 4d-115.0341086! 3m4! 1s0x80c8d0ee15946fab : 0xf63c089de79dc407! 8m2! 3d36.0659811! 4d-115.0333684? Hl = de) –

+0

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3DU.%%252095%2520% 2526% 2520W% 2520sunset% 2520rd% 252C% 2520las% 2520vegas. Sie sollten die Adresse so genau wie möglich formatieren. – xomena

Verwandte Themen