Solved

How to get multiple addresses from a SQL database into an embedded Google Map?

Posted on 2009-05-14
3
650 Views
Last Modified: 2013-12-12
I have a Google map embedded on my site that dynamically generates by taking the address and zip code from a SQL database. I am not bothering w/ coordinates, and I am happy with the results so far. The code I use is listed below (with a made-up address and zip, normally would get value from the database), and works just fine for one address.

However, there are some pages that will result in multiple addresses, and I'd like to generate multiple markers on the map to represent those addresses. I am using PHP. Any ideas?
$address = "111 South Main Street";
$zip = 55555;
 
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"  src="http://maps.google.com/maps?
f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?php echo $address;?>,+<?php echo $zip;?>&amp;ie=UTF8&amp;z=14&amp;output=embed">
</iframe>

Open in new window

0
Comment
Question by:oh_maestro
  • 2
3 Comments
 
LVL 5

Expert Comment

by:TheVeee
ID: 24387205
If Im following you right, you may need to rethink how your storing your addresses to add a type field and a association table.  That way you will be able to distinguish which address each one is and then also put layers on the display if wanting know each one separately via  a layer.

I would have three tables....

1.  Customer table (Like before with Customer Id as primary Key)
2.  Address table with just AddressId with fields AddressId, Address,City,State, Zip
3.  The a customer address association table which would have keys CustomerId, AddressId, AddressType.

Data would look like:
Customer:

CustomerId:1111
CustomerFirstName: Larry
CustomerLastName: Smith
CustomerDOB:04/07/1992

Address Table:
AddressId:12
Address: 514 N. Meadowbrook
City: Olathe
State: KS
Zip: 66102

Customer_Address_Assocation:
CustomerId:1111
AddressId:12
AddressType:Mailing

Then sql would be Select A.CustomerFirstName, A.CustomerLastName, A.CustomerDOB, B.Address, B.City, B.State, B.Zip from CustomerTable A, AddressTable B, CustomerAddressAssocation C where
B.AddressId = C.Address_ID and A.CustomerId = B.CustomerId and B.AddressType = "MAILING"

This one would only bring back the mailing address.  If I had other address "types" for the user (physical, work, etc), I would then just have another AddressType for each one.  That way I can use the address over and over and save it one place.  
0
 

Author Comment

by:oh_maestro
ID: 24387380
I don' t have a problem getting the correct address(es) from the database.

Say the query would return 3 addresses and zips.

I would like to have 3 markers on an embedded Google map to represent the location of the 3 houses/businesses based on the address and zip code.
0
 

Accepted Solution

by:
oh_maestro earned 0 total points
ID: 24406505
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL limit and not so limited 13 40
php error 27 58
Pull Variable from URL  Use php template 1 35
scan php uploads for viruses 5 26
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question