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

强颜欢笑 提交于 2019-11-30 03:58:52

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.

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;

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