Does the v3 Google Maps Geocoding API have a field that represents accuracy?

百般思念 提交于 2019-11-29 01:36:36

问题


I have some code that I'm porting over from API v2 to v3. In the old code we had an accuracy field that came back in the xml (not sure of the name, but it did represent a confidence level of sorts). In the new API, I don't see any field like that.

If I put "Oregon, USA" into the search field I get 5 matches. The first 2 are "Oregon, USA" and "Oregon, OH, USA". They both have "partial_match" = false. This doesn't seem right, one seems partial and one doesn't. Plus, they're both coming back with the same "location_type" (APPROXIMATE). In fact, all matches are showing as not-partial and have same location type.

My question is, do any of the fields in the result set convey some sort of confidence in the accuracy of the result? In my sample it really seems like one result is much more accurate than any other -- so much so that the input string exactly matches the QuickAddress field that's returned.


回答1:


Two weeks, no answers, so here's my solution.

The API will return either ROOFTOP, GEOMETRIC_CENTER, RANGE_INTERPOLATED or APPROXIMATE.

Rooftop is essentially "dead on" -- the API resolved the address to a building. Other than that, you get varying degrees of "close". My solution was to use the bounding box that was returned to determine how close close was. So if you ask for a street (Avenue of the Americas, NY, NY) you'll get a huge bounding box. Ask for an address on that street that the API thinks is an actual address but isn't a Rooftop, you'll get a very small bounding box. I used the area of the bounding box to determine the accuracy of the result. My accurate/not accurate break was at 0.9E-6 but I think you'd have to tinker with it to make sure you are comfortable with that number.




回答2:


I have found this useful when updating legacy V2 code dependent on a 0 to 9 score
//Hack to convert location_type (string) to 0-9 Geocode score as 0-9 Geocode score doesn't exist in v3 API

function get_numeric_score(results) {
switch(results[0].geometry.location_type){
        case "ROOFTOP":
            return 9;
        break;

        case "RANGE_INTERPOLATED":
            return 7;
        break;

        case "GEOMETRIC_CENTER":
            return = 6;
        break;

        case "APPROXIMATE":
            return 4;
        break;

        default:
            return 0;

    }
}


来源:https://stackoverflow.com/questions/7474076/does-the-v3-google-maps-geocoding-api-have-a-field-that-represents-accuracy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!