Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm listing businesses on my site, that gets auto displayed by the data the users submitted and sent to my database. The question is, how to build an iframe google map link to display the current business's location?


<div id="data"><div id="list">
    <p class="county">County:<?php echo $data['county']??''; ?></p>
    <p>City: <?php echo $data['city']??''; ?> <?php echo $data['post']??''; ?></p>
    <p>Phone: <?php echo $data['phone']??''; ?></p>
    <p>EMAIL: <?php echo $data['email']??''; ?></p>
    <p class="brand">Brand:<?php echo $data['brand']??''; ?></p>
</div>


What I have tried:

I was thinking about something like this:

<iframe src="https://www.google.com/maps/search/?api=1&'<?php echo $data['post']??''; ?>'+'<?php echo $data['city']??''; ?>'+'<?php echo $data['street']??''; ?>'+'<?php echo $data['number']??''; ?>'"></iframe>


Any help would be appreciated!
Posted
Updated 6-Mar-23 0:54am

1 solution

You can't embed the maps in an iframe directly; you would need to obtain an API key and use the Google Maps API:
Google Maps Platform  |  Google Developers[^]

Based on my own experience, you will need to add a payment method to your account so that they can bill you if your usage exceeds the limits of the free tier.

There's also a "Maps Static API" for simpler integrations:
Overview  |  Maps Static API  |  Google Developers[^]

You still need to create an account and add a payment method to use that.

There are free alternatives which you can embed without setting up an account - for example: OpenStreetMap[^]
 
Share this answer
 
Comments
István Balogh 6-Mar-23 6:59am    
Thanks for your comment! Is there a way to auto generate a map with the current businesses address in my listing?
Richard Deeming 6-Mar-23 7:04am    
With Google Maps, the Places API[^] will let you search for an address. The quality of the results will depend on the quality of the address.

Otherwise, you'd need to store the latitude and longitude of the address you want to display.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900