How to use CORS to implement JavaScript Google Places API request

前端 未结 2 2117
旧巷少年郎
旧巷少年郎 2020-11-28 14:52

I really do NOT understand how I\'m supposed to make this work:

var requestURL = \'https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tD         


        
2条回答
  •  渐次进展
    2020-11-28 15:38

    You are trying to use the Google Places API Web Service on client side whereas it is designed for server side applications. That's probably why appropriate CORS response headers are not set by the server.

    As explained in the Notes at the beginning of the Place Details documentation, you should use the Places Library in the Google Maps JavaScript API:

    If you're building a client-side application, take a look at the Google Places API for Android, the Google Places API for iOS, and the Places Library in the Google Maps JavaScript API.

    Note: you will need to enable the Google Maps JavaScript API in your Google Developer Console first.

    Here is a way you can proceed to get place details (based on the example from the documentation):

    
        
        
    
    
        

提交回复
热议问题