How do we use Google Maps to show locations of sellers?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do we use Google Maps to show locations of sellers?

Post by simonmlewis »

We are setting up a sales website for users to sell their own unique products.

We want the buyer to be able to see the location of the seller, down to their street name, in an embedded window.

I saw this:
http://html.shellcreeper.com/map-bound/
But it has to do it with the Long and Lat which we cannot get the seller to location.
So how do we do it? Does that information get sources dynamically from a Google API, and stored in a variable which then goes into our database, and if so, how?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do we use Google Maps to show locations of sellers?

Post by requinix »

You can use the Google Maps API server-side to look up the seller's address and get a lat/long. Store that in your database and use it with the map.

You could do the lookup on the client, but it will be the same value every time so there's no sense waiting until then.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do we use Google Maps to show locations of sellers?

Post by simonmlewis »

I just found a brilliant bit of code that does it.

Code: Select all

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<?php 
$address_variable = "street here, town, postcode";
 $address = str_replace(" ", "+",$address_variable);
?>
<iframe style="width:100%;height:50%;" frameborder="0" id="cusmap" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?q=<?php echo $address; ?>&output=embed"></iframe>

Works just fine. No need for Lat and Long, even though I have since found a script that can gather it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: How do we use Google Maps to show locations of sellers?

Post by thinsoldier »

The google maps team has a github account with lots of example code for many thing you'd want to do like this and others

https://googlemaps.github.io/libraries

example: https://github.com/googlemaps/js-marker-clusterer
Warning: I have no idea what I'm talking about.
pass4sureguide
Forum Newbie
Posts: 1
Joined: Tue May 31, 2016 1:17 am

Re: How do we use Google Maps to show locations of sellers?

Post by pass4sureguide »

good point:

use the Google Maps API server-side to look up the seller's address and get a lat/long. Store that in your database and use it with the map..
Last edited by requinix on Tue May 31, 2016 2:53 am, edited 1 time in total.
Reason: removing advertising
Post Reply