You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在App Maker中调用PlacesServices的getDetails函数?

Using PlacesService.getDetails() in App Maker with a Place ID

Absolutely! You can absolutely use the Google Places Service's getDetails() function within App Maker to pull detailed information for a Place ID you've retrieved via Geocoder. Here's a practical breakdown of how to make this work:

Step 1: Enable the Places API in your Google Cloud Project

Since App Maker is linked to your Google Cloud Project (GCP), first make sure the Places API is enabled:

  • Head to your GCP Console, go to APIs & Services > Library
  • Search for "Places API" and enable it if it’s inactive
  • Verify your App Maker project has valid credentials (API key or OAuth) set up in the App Maker settings under "API Access" to access the API

Step 2: Implement the getDetails() call

You can add this logic either in client-side scripts (for UI-driven interactions) or server-side scripts (for backend processing). Here are examples for both:

Client-side Script Example

function fetchPlaceDetails(placeId) {
  // Initialize PlacesService with a hidden container element
  var service = new google.maps.places.PlacesService(document.createElement('div'));
  
  service.getDetails({
    placeId: placeId
  }, function(place, status) {
    if (status === google.maps.places.PlacesServiceStatus.OK) {
      // Use the retrieved place data to update your App Maker UI
      console.log('Place Details:', place);
      app.pages.YourPage.widgets.PlaceName.value = place.name;
      app.pages.YourPage.widgets.FullAddress.value = place.formatted_address;
      app.pages.YourPage.widgets.PhoneNumber.value = place.formatted_phone_number;
    } else {
      // Handle error scenarios
      console.error('Failed to load place details:', status);
      app.showAlert('Could not retrieve place information. Please try again.');
    }
  });
}

Server-side Script Example

If you need to fetch details backend-side (e.g., for data storage or automated processing), use the Google Apps Script Places Service:

function getPlaceDetailsServerSide(placeId) {
  var place = PlacesService.getPlaceById(placeId);
  if (place) {
    Logger.log('Server-side Place Data:', place);
    return {
      name: place.getName(),
      address: place.getAddress(),
      website: place.getWebsite()
    };
  } else {
    throw new Error('Invalid Place ID or place not found');
  }
}

Step 3: Important Checks

  • Load the Maps JavaScript API: Add this to your App Maker project's "External Resources" to access the PlacesService:
    <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script>
    
  • Quota & Permissions: Monitor your GCP dashboard to stay within Places API usage limits, and restrict your API key to your App Maker domain to prevent unauthorized use
  • Data Access: The returned place object includes tons of data (opening hours, reviews, ratings, etc.)—you can access these properties based on your app’s specific needs

内容的提问来源于stack exchange,提问作者Cleo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:15:36