PottyPin Demo & API Documentation

No data received.

URI: https://pottypin.appsbycarla.com/api.php?api={YOUR_API_KEY}&endpoint={ENDPOINT_OPTIONS}

ENDPOINT OPTIONS:
place_id - cross referenced to Google Places API Decoded JSON ['place_id']

Technologies Used:
PHP - A popular server-side scripting language.

JavaScript - A client-side scripting language. Google Places API - A service by Google that provides information about local businesses and other points of interest.
HTML & CSS - Used for structuring and styling the web pages.

Geolocation Algorithm:

  1. Initialize the session and database connection: The PHP session is started to allow for storing and retrieval of session variables, and a database connection is initiated using 'db.php'.
  2. Check for Location Data in Session:
    1. Verify if the geolocation data (lat and lng) is set in the session.
    2. If not available, the script terminates with a message "Location not set in session."
  3. Retrieve Nearby Places:
    1. Use the stored lat and lng values from the session to query the Google Places API.
    2. Fetch nearby places of interest (e.g., restaurants, gas stations, drugstores) within a specific radius.
    3. Combine results from each type of place into a single array called combinedResults.
  4. Sort Combined Results:
    1. Use the calculateDistance function to measure the distance between the user's location and each place's location.
    2. Sort the combinedResults array based on distance, with the nearest places appearing first.
  5. Fetch Data from Local Database:
    1. Extract place IDs from Google's results and then query the local database (table named 'kubetas') to fetch additional details about these places.
    2. Merge the local database results with the combinedResults from the Google Places API.
  6. Edit Place Data:
    1. On accessing edit.php, it first connects to the database and checks for a given place ID.
    2. If the place ID is found in the local database, fetch and display its details. Otherwise, retrieve the place's details from the Google Places API.
    3. Upon form submission, check if the place already exists in the database.
    4. If it exists, update the record; otherwise, insert a new record into the 'kubetas' table with the provided details.
  7. Redirect: After updating or inserting the place details in edit.php, redirect the user back to the results.php page.

Tech Stack: