I'm not sure if this should be in this forum but I figured it was a good starting place. I am creating a database that, among other things, allows users to input a store's location (e.g. name, address, etc). Once a store has been added, there is an ability to go into a single store's "page" to view all of it's information including name, contact info, reviews, comments, etc. What I would really like is the ability for a Google Map to generate automatically when the page loads with the store's name and address listed (and pulled up in the window).

Does anyone have any idea as to how this might work or, better yet, anyone have any experience doing this first hand?

Thanks!

Dani AI

Generated

Short practical plan that builds on and : store a store's latitude/longitude in your table and render a Google map on the store page from those coordinates. Pre-geocode addresses when they are added or edited (so the page loads fast and you avoid repeated geocoding on every view). Use the Maps JavaScript API to draw the map and marker from stored values. Maps JavaScript API. (developers.google.com)

How to get those coordinates: either (A) server-side geocode the address at insert/update time with the Google Geocoding web service, or (B) geocode client-side when the user enters an address (useful for live validation). Google now requires an API key and a billing-enabled project for Geocoding; review quotas and cost controls before batch-processing many rows. Set up the Geocoding API. Optimizing quota usage. (developers.google.com)

Minimal examples (schema + flow):

ALTER TABLE stores
  ADD latitude DECIMAL(10,7) DEFAULT NULL,
  ADD longitude DECIMAL(10,7) DEFAULT NULL;

Server-side: request https://maps.googleapis.com/maps/api/geocode/json?address=...&key=YOUR_KEY, parse results[0].geometry.location and save lat/lng. On the store page echo the numbers into JS and init the map:

<script>
const myLatLng = { lat: <?= $lat ?>, lng: <?= $lng ?> };
function initMap(){ const map = new google.maps.Map(...); new google.maps.Marker({ position: myLatLng, map }); }
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&callback=initMap" async defer></script>

Keep calls simple, check status, and handle missing/ambiguous results. Google Geocoding has storage/caching rules (lat/lng may only be cached briefly — see Geocoding policies) so consider storing the Place ID for refresh and obey the 30-day rules if you cache results. Geocoding policies and terms. (developers.google.com)

Operational tips: batch-geocode slowly with rate limits in mind, add exponential backoff, and restrict your API key. If Google’s terms or cost are a problem, lightweight alternatives exist (OpenStreetMap/Nominatim but with strict public-API usage limits — e.g. ~1 req/sec — or run your own instance). For DB precision use 6–7 decimal places (6 decimals ≈ 0.11 m resolution at the equator). Nominatim usage policy. Decimal precision. (operations.osmfoundation.org)

Recommended Answers

All 6 Replies

This might be helpful

I believe this one has a simpler approach. What you need is two columns in your table latitude and longitude then just use them to insert a Google map with them as location. Before that get acquaintance with Google Map and make your own JavaScript function to make it easy for you (in order PHP to call only these functions with longitude / latitude). Of course after that you could make a step further adding what kind of icon you like for spot and what info for the bubble box in your database.

I believe this one has a simpler approach. What you need is two columns in your table latitude and longitude then just use them to insert a Google map with them as location. Before that get acquaintance with Google Map and make your own JavaScript function to make it easy for you (in order PHP to call only these functions with longitude / latitude). Of course after that you could make a step further adding what kind of icon you like for spot and what info for the bubble box in your database.

I guess the next question then would be how to I figure out Longitude/Latitude based on a complete address?

Hi,

Its very simple you just need to create database in MySQL. Suppose your database will be as under.

You need to make database which contains following:

Store Name
Add1
Add2
City
Pincode
Latitude
Longitude

After creating and filling some data in it you need to Integrate google map in to your website which work based on Lan & Lon.

When ever the particular store link clicked, the Lat,and Lon retrieved based on store id and passed to Google Map to display marker at that Lat & Lon.

See the step by step tutorial How To integrate Google Map. On this tutorial Google Map implimantation explained with example.

I am using the Amerra Connect SDK to show the map by searching a physical address. It requires just one line to call a function if you have the Amerra Connect SDK.

See for more information.

For searching "45 Rockefeller Plaza, New York, NY 10111", you just need:

<?php
    include("../lib/AmerraConnect.php");
    $amerraconnect = new AmerraConnect();
    echo $amerraconnect->showMap("45 Rockefeller Plaza, New York, NY 10111", "Rockefeller Center", "800", "800");
?>

For more information, visit

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.