Google-maps-locationbeginner Level 30 min read Afzaal Suleman

Google Maps Location APIs

Google Maps APIs for address autocomplete, geocoding, map selection, and delivery-area distance checking in the Shoqis Pizza checkout.

#Google Maps#Places API#Autocomplete#Geocoding Maps#JavaScript API#Routes API#Delivery Radius
Google-maps-location Study Chapter · Official Reference

APIs Used

1. Maps JavaScript API

Purpose: Display the interactive Google Map in the React frontend.

Used for:

  • Showing the map

  • Moving the map

  • Clicking on the map

  • Dragging the marker

  • Selecting latitude/longitude

Frontend example:

https://maps.googleapis.com/maps/api/js

2. Places Autocomplete API

Purpose: Show address/location suggestions while the customer types.

Example:

Customer types:
"isb"

Google returns:
Islamabad, Pakistan
Islamabad International Airport
Islamabad Capital Territory
...

Current Laravel endpoint:

GET /checkout/autocomplete?query=isb

Current Google endpoint:

https://maps.googleapis.com/maps/api/place/autocomplete/json

Important: Google returned:

REQUEST_DENIED
You must enable Billing on the Google Cloud Project

Therefore, billing must be enabled on the Google Cloud project connected to the API key.


3. Geocoding API

Purpose: Convert an address into latitude and longitude.

Example:

"Islamabad, Pakistan"
        ↓
lat: 33.6844
lng: 73.0479

Current Laravel service:

GoogleMapsGeocodingService

Endpoint:

https://maps.googleapis.com/maps/api/geocode/json

4. Routes API / Distance Calculation

Purpose: Calculate driving distance and travel time between restaurant and customer.

Example:

Restaurant
    ↓
  driving
    ↓
Customer
    ↓
8.4 km

For a simple delivery radius, such as:

Restaurant radius = 10 km

we can use the existing Haversine calculation locally instead of making a Google request.

This can reduce API usage.


Recommended Checkout Flow

Customer enters address
          ↓
Places Autocomplete
          ↓
Customer selects suggestion
          ↓
Get latitude + longitude
          ↓
Check delivery area
          ↓
┌───────────────────────┐
│ Within delivery area? │
└───────────────────────┘
       ↓           ↓
      YES          NO
       ↓           ↓
   Continue      Reject
   checkout      delivery

Google APIs vs Local Calculation

Requirement

Recommended

Display map

Maps JavaScript API

Address suggestions

Places Autocomplete

Address → coordinates

Geocoding API

Simple 10 km radius

Haversine calculation

Actual driving distance

Routes API

Address validation

Address Validation API

Important

Google Maps Platform requires billing to be enabled for the project for the Google service currently being used.

error:

REQUEST_DENIED
You must enable Billing on the Google Cloud Project

✦✦✦
Google Maps Location APIs | Google Maps Location Guide | Afzaal Suleman