我正在使用Search YELP API开发移动应用程序。我想在谷歌地图上显示几个商家。 但不幸的是,我没有收到业务中的所有坐标对象。
"location":{
"neighborhoods":[
"West Ham",
"Stratford"
],
"state_code":"XGL",
"display_address":[
"409 High Street",
"West Ham",
"London E15 4QZ",
"UK"
],
"coordinate":{
"longitude":-2.16E-4,
"latitude":51.53907
},
"address":[
"409 High Street"
],
"postal_code":"E15 4QZ",
"geo_accuracy":5,
"country_code":"GB",
"city":"London"
},
我应该如何面对这个问题?是否有任何解决方法可以在地图上显示我的业务?
答案 0 :(得分:0)
我刚刚找到了问题的答案。
如果未提供坐标,我可以使用
提供的geocoding格式化我的请求,如下所示:
// Replace the API key below with a valid API key.
GeoApiContext context = new GeoApiContext().setApiKey("AIza...");
GeocodingResult[] results = GeocodingApi.geocode(context,
"1600 Amphitheatre Parkway Mountain View, CA 94043").await();
System.out.println(results[0].formattedAddress);
类似于:https://maps.googleapis.com/maps/api/geocode/json?address=54+Frith+Street,+London,+GB
API给我一个JSON:
{
"results" : [
{
"address_components" : [
{
"long_name" : "54",
"short_name" : "54",
"types" : [ "street_number" ]
},
{
"long_name" : "Frith Street",
"short_name" : "Frith St",
"types" : [ "route" ]
},
{
"long_name" : "Soho",
"short_name" : "Soho",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Soho",
"short_name" : "Soho",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "London",
"short_name" : "London",
"types" : [ "locality", "political" ]
},
{
"long_name" : "London",
"short_name" : "London",
"types" : [ "postal_town" ]
},
{
"long_name" : "Greater London",
"short_name" : "Gt Lon",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "United Kingdom",
"short_name" : "GB",
"types" : [ "country", "political" ]
},
{
"long_name" : "W1D 4SL",
"short_name" : "W1D 4SL",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "54 Frith Street, Soho, London W1D 4SL, UK",
"geometry" : {
"location" : {
"lat" : 51.5137474,
"lng" : -0.1318321
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 51.5150963802915,
"lng" : -0.130483119708498
},
"southwest" : {
"lat" : 51.5123984197085,
"lng" : -0.133181080291502
}
}
},
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
希望在这种情况下它可以帮助其他人!