Google Maps Place Details API不返回电话号码 [英] Google Maps Place Details API Not Returning Phone Numbers

查看:74
本文介绍了Google Maps Place Details API不返回电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在致电地方详情".我想找回电话号码(formatted_phone_number).该字段未返回,我在响应中看不到任何电话号码.我将fields属性设置为null以获取所有可用属性

I'm making a call to Place Details. I want to get the phone number(formatted_phone_number) back. That field isn't being returned and I don't see any phone numbers in the response. I set the fields property to null to get all of the available properties

const placeDetails = (result) => {
    console.log('placeDetails');

    const request = {
        placeId: result.place_id,
        fields: null //['name', 'formatted_phone_number', 'rating', 'reviews', 'website']
    };

    service.getDetails(request, placeDetailsCb);
}

const placeDetailsCb = (place, status) => {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
        console.log('place', place)
    }
    else {
        console.log(`Place Details Response not OK. Status: ${status}`)
    }
}

响应

对象{address_components:(9)[…],adr_address:"563 2nd St,San Francisco,CA 94107-1411,USA",formatted_address:"563 2nd St, 美国加利福尼亚州94107,旧金山",几何图形:{…},图标: " https://maps.gstatic.com/mapfiles/place_api/icons /geocode-71.png ", id:"69cfece0624106a3c1dc8669ffa975fb6464faeb",名称:"563 2nd St", place_id:"ChIJrfXAU3iAhYARyUGceTIdcMg",参考: "ChIjrfXAU3iAhYaryUGceTIdcMg",范围:"GOOGLE",…} api.js:57:17

Object { address_components: (9) […], adr_address: "563 2nd St, San Francisco, CA 94107-1411, USA", formatted_address: "563 2nd St, San Francisco, CA 94107, USA", geometry: {…}, icon: "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png", id: "69cfece0624106a3c1dc8669ffa975fb6464faeb", name: "563 2nd St", place_id: "ChIJrfXAU3iAhYARyUGceTIdcMg", reference: "ChIJrfXAU3iAhYARyUGceTIdcMg", scope: "GOOGLE", … } api.js:57:17

我也尝试了附近的地方"搜索和自动完成"搜索.按类型=建立方式进行的自动完成过滤不会返回任何结果,仅保留返回的前提和地理编码类型(而不是建立方式)的过滤器即可.

I also tried both the Nearby Places search and Autocomplete search. The Autocomplete filtering by type=establishment didn't return any results and leaving off that filter only returned premise and geocode types, not establishement.

https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api/place/autocomplete/json?input=563 2nd St, San Francisco, CA 94107, USA&type=establishment&key=<APIKEY>
https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api/place/autocomplete/json?input=563 2nd St, San Francisco, CA 94107, USA&key=<APIKEY>

附近的搜索"确实返回了场所,但maps.google.com中没有出现的场所(

The Nearby Search did return establishments, but not the one that comes up in maps.google.com (establishment)

https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.7825321,-122.3946465&radius=10&type=establishment&key=<APIKEY>

推荐答案

位置ID ChIJrfXAU3iAhYARyUGceTIdcMgpremise类型.它的地址是563 2nd St, San Francisco, CA 94107, USA,在

Place ID ChIJrfXAU3iAhYARyUGceTIdcMg is of premise type. Its address is 563 2nd St, San Francisco, CA 94107, USA which has no public phone number in Google Maps either. Hence the Places API cannot possibly return a phone number because there just isn't one. This is a house.

为了获取formatted_phone_number,您需要搜索establishment(商业)类型的地点.因此,如果您不是在上述前提下而是在餐厅旁边搜索餐厅,即21st Amendment Brewery & Restaurant(地点ID为ChIJYwMBJ-l9hYAR66sAdy3sjKQ),则会获得一个电话号码,该电话号码与

In order to get formatted_phone_number, you need to search for places of establishment (business) type. So if instead of the above premise, you search for the restaurant next to it, i.e. 21st Amendment Brewery & Restaurant (place ID ChIJYwMBJ-l9hYAR66sAdy3sjKQ), you will get a phone number, the same one shown in Google Maps.

看看这个jsfiddle for Places Details演示: https://jsfiddle.net/v8mfzy4r/

Take a look at this jsfiddle for Places Details demonstration: https://jsfiddle.net/v8mfzy4r/

作为副节点,可以从地点自动完成"和地点搜索"服务中检索地点ID,并且您可以将结果限制为特定的类型,例如establishment(对于自动完成")或其任何子类型,例如restaurant(用于位置搜索).

As a side-node, place IDs can be retrieved from the Place Autocomplete and Place Search services and you can restrict results to a specific type such as establishment (for Autocomplete) or any of its subtypes, e.g. restaurant (for Place Search).

Google的文档中对此进行了详细说明,我建议您需要花费一些时间,尤其是因为这是一个可结算库和联系方式数据SKU字段需要支付额外费用.

This is all explained in detail in Google's documentation which I recommend you take some time to go through, especially because this is a billable library and Contact Data SKU fields have an additional cost.

希望这会有所帮助!

这篇关于Google Maps Place Details API不返回电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆