从文本通过谷歌地图获取道路位置api
我有一个*文本,我需要转换为坐标,但文本旨在道路和道路注入。从文本通过谷歌地图获取道路位置api
问题是,谷歌api地理编码服务返回附近的建筑物,但我需要自己的道路。
例如: 搜索在拉斯维加斯US95和日落返回
{
"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"
}
,但我需要真正的坐标为:36.063761 -115.032024。
任何建议如何获得道路坐标?
我建议对美国的道路下面的建议的格式,你可以在
https://developers.google.com/maps/faq#geocoder_highways
于是发现,在你的情况下,搜索字符串应该是“美国95 &日落,拉斯维加斯”。相应请求将(注意URL编码的搜索字符串)
https://maps.googleapis.com/maps/api/geocode/json?address=U.S.%2095%20%26%20sunset%2C%20las%20vegas&key=YOUR_API_KEY
该请求将返回类型相交的一个结果如图我的截图
你也可以看到这一点地理编码工具:
我希望这有助于!
这太棒了!我会检查它并让你知道。顺便说一句,任何想法如何查询i215和远山大道(也拉斯维加斯)?我在问,因为在这一部分,i215是一个公司,所以它变得更加复杂(i215既可以是州际公路,也可以是一条乡村公路'布鲁斯伍德伯里环路')。 –
刚刚意识到它不是想要的地方。我想'W sunset Rd',默认情况下它会返回'Sunset Dr',这是一条较小的道路。任何方式来优先考虑道路类型的结果? [这是现货](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 +退伍军人纪念+高速公路+ +%26 + US-93,+亨德森,+ NV + 89014 3B18平方米3d36.0669328 4D-3M4 115.0341086 1s0x80c8d0ee15946fab!! :0xf63c089de79dc407!8m2!3d36.0659811!4d-115.0333684?hl = en) –
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3DU.S.%252095%2520% 2526%2520W%2520sunset%2520rd%252C%2520las%2520vegas。你应该尽可能精确地格式化地址。 – xomena
在你的例子中,第一个项目有类型“路线”,它不是建立。该位置可以在地理编码器工具中查看:https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D36.063505%252C-115.033649。它看起来像这个例子按预期工作。 – xomena
是的,但想要的坐标从结果中排除 –