Jump to content

looking for options...parse address from DB to Map form???


slashpine

Recommended Posts

Not sure if this is kosher or not...?

I have a database of local business listings... without having to hand code every record (over 50k)...I would like to add a link to a map of the address that coincides with each individual record...

Can this be done with a single script?

could it possibly be done using an html form grabbed from the source code of a free map provider (and hiding the fields) that executes a script that grabs the record from the DB and parses the streed address and the zip code ...this would leave me a "map" button rather than a (text) hyperlink..

any comments or suggestions welcome...
Link to comment
Share on other sites

You need to know four things

the x,y coordinates (lat, long) of the business
the coordinates of top-left of the map
the coordinates of bottom-right of the map
the dimensions of the map on the page

Once you know those you can scale the coordinates and place the business in the correct place on the map
Link to comment
Share on other sites

[quote author=slashpine link=topic=106136.msg424238#msg424238 date=1156882180]
What I have in the database in corresponding columns= 'street address' | 'zip code'

do I have any options using this data?
[/quote]

Yes. Yahoo Maps or Google Maps. Either of them conditionally allow the use of their maps.  If you visit one of the addresses in your database you'll see how map services construct their URLs and then you can use your database info to construct specific URLs for each of the businesses that link to the right part of the right map.
Link to comment
Share on other sites

[quote author=AndyB link=topic=106136.msg424252#msg424252 date=1156884938]
[quote author=slashpine link=topic=106136.msg424238#msg424238 date=1156882180]
What I have in the database in corresponding columns= 'street address' | 'zip code'

do I have any options using this data?
[/quote]

Yes. Yahoo Maps or Google Maps. Either of them conditionally allow the use of their maps.  If you visit one of the addresses in your database you'll see how map services construct their URLs and then you can use your database info to construct specific URLs for each of the businesses that link to the right part of the right map.
[/quote]

Thanks...

I see what you mean...can I use php to query the database and  parse the address and zip  as variables and displays the dynamioc URL ?
Link to comment
Share on other sites

[quote]can I use php to query the database and  parse the address and zip  as variables and displays the dynamioc URL ?[/quote]

Exactly so. I've used that on real estate sites to provide a direct link to the right part of Yahoo Maps from a clickable image on my client's site.
Link to comment
Share on other sites

ok I think I got a handle on it but....The "address" record I have is a usually a street number and then a street name etc... all the URLs for the map sites have +'s between the number and the street name... the way I thought to call the data "...{$data['address']}..."  I don't know how to seperate the number and the street name in the string from that column with a +

?
Link to comment
Share on other sites

How you do that really depends on how the address in your database is formatted, but for the street address str_replace() is the function you'll need.

Below is a working example I used where addr1 was a street address, addr2 was the zip, and the country was presumed to be US.

[code]    $url = "http://us.rd.yahoo.com/maps/us/insert/Tmap/extmap/*-http://maps.yahoo.com/maps_result?addr=";
    $url.= str_replace(" ","+",$query_data['addr1']);
    $url.= "&csz=";
    $url1 = str_replace(",","%2C",$query_data['addr2']);
    $url.= str_replace(" ","+",$url1). "&country=us";
    echo "<a href='". $url. "'><img src='images/maplink.gif' width='89' height='17' alt=''/></a>";[/code]
Link to comment
Share on other sites

I know my code works. All I did was to go to one of the addresses in my database (manually entered at Yahoo), then zoom to whatever scale I wanted etc.  There's a link on the map page that says 'copy this to add this map to your site' ... or something like that ... which leads you to a text box with the precise html code for a link to that address on that map.

Then I just worked backwards from that html code to determine how I could use my own real database information to construct a similar link to an address from the database.  It always worked.

I notice that your map URL is different from the one I used. Maybe if you follow the process I've outlined above you'll be able to get your stuff working.
Link to comment
Share on other sites

  • 3 weeks later...
[code]I think I have finally gotten this script to work...however I have encountered  a problem with one database that does not have complete zip code records for all records...

can the author or anyone else help me so in place of a ZIP code the script will parse (the address and)  the "city"  with the state being a constant similar to the way the county is in the example below??

[code]$url.= str_replace(" ","+",$data['address']);
    $url.= "&amp;csz=";
    $url1 = str_replace(",","%2C",$data['zip']);
    $url.= str_replace(" ","+",$url1). "&amp;country=us";[/code]

I can see enough to replace $data 'zip'  with $data'city'.... but I am not sure about the State (GA)

TIA


edited I got this by changing zip to city and adding ",GA+ to

    $url.= str_replace(" ","+",$url1). "[color=red],GA+[/color]&amp;country=us";[/code]
Link to comment
Share on other sites

[quote author=AndyB link=topic=106136.msg424391#msg424391 date=1156898565]
How you do that really depends on how the address in your database is formatted, but for the street address str_replace() is the function you'll need.

Below is a working example I used where addr1 was a street address, addr2 was the zip, and the country was presumed to be US.

[code]    $url = "http://us.rd.yahoo.com/maps/us/insert/Tmap/extmap/*-http://maps.yahoo.com/maps_result?addr=";
    $url.= str_replace(" ","+",$query_data['addr1']);
    $url.= "&amp;csz=";
    $url1 = str_replace(",","%2C",$query_data['addr2']);
    $url.= str_replace(" ","+",$url1). "&amp;country=us";
    echo "<a href='". $url. "'><img src='images/maplink.gif' width='89' height='17' alt=''/></a>";[/code]
[/quote]

Thanks for your previous help...I have this scritp working both with zip codes and city/state parameters...

Now is there anything that can be done about addresses that characters like # 3 or #A

Thanks in advance
Link to comment
Share on other sites

The only thing that comes to mind is to go to maps.yahoo.com and enter one of those 'problem' addresses to see exactly what URL Yahoo constructs to find the right map, etc. or how it handles (or ignores) things that look like apartment numbers, and then work backwards from there.  That's how I solved the problem I had in the first place and now both us know it's possible and produces a pretty reasonable result (after a few aspirin and some trial and error).
Link to comment
Share on other sites

ok thanks give that approach a shot and will post any progress...

your efforts are very much appreciated... the snippet works great...

With some trial and errors I have managed to make it work very well for me...

I have noticed that if the user has been using the new (beta) version of Yahoo maps (ala google) it works just as well and URL in the script works with both version of Yahoo Maps...depending on what the  user's browsers has been set to use...

Thanks again... I suppose some day I will have to go with geo coding etc.. but for now your script works great with my current databases...

thumbs up and hats off to you...
Link to comment
Share on other sites

I just wanted to post this solution to the "#" character problem for anyone else that may encounter the glitch...

for some reason the script or the URI would not accept (symbol) characters...in this case the # sign...

After messing with the application and seeing how the map host handled the problem (as advised by 'AndyB') I surmised that changing the # to the word "Unit" solved the problem...

I used an UPDATE-Replace query to change all the records in the database

All is well... thanks for all the great help and suggestions...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.