472,125 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

How to add multiple pinpoints on Google maps from mysql database using PHP?

194 100+
Hi everyone,

I am trying to add multiple pinpoint to google map using Lon/Lat. All addresses will be fetched from mysql database using PHP.

I have looked at google and searched for it on various sites but nothing helpful i found.

i have used the following code which worked for only one address whereas i have alot of addresses.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  6. <title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
  7. <link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
  8. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  9. <script type="text/javascript">
  10.   var geocoder;
  11.   var map;
  12.   function initialize() {
  13.     geocoder = new google.maps.Geocoder();
  14.     var latlng = new google.maps.LatLng(-34.397, 150.644);
  15.     var myOptions = {
  16.       zoom: 8,
  17.       center: latlng,
  18.       mapTypeId: google.maps.MapTypeId.ROADMAP
  19.     }
  20.     map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  21.   }
  23.   function codeAddress() {
  24.     var address = 'Sydney, NSW';
  25.     geocoder.geocode( { 'address': address}, function(results, status) {
  26.       if (status == google.maps.GeocoderStatus.OK) {
  27.           initialize();
  28.         map.setCenter(results[0].geometry.location);
  29. /*        var marker = new google.maps.Marker({
  30.             map: map, 
  31.             position: results[0].geometry.location
  32.         });*/
  34.         var marker = new google.maps.Marker({
  35.   position: new google.maps.LatLng+results[0].geometry.location, 
  36.   map: map, 
  37.               position: results[0].geometry.location,
  38.   title:"Hello World!"});  
  39.       } else {
  40.         alert("Geocode was not successful for the following reason: " + status);
  41.       }
  42.     });
  43.   }
  44. </script>
  45. </head>
  46. <body onload="initialize();codeAddress();">
  48. <div id="map_canvas" style="height:90%"></div>
  49. </body>
  50. </html>
Please tell me how i can add multiple pin points to google map. I dont wana use static map.

Thanking you.

Jan 17 '11 #1
6 15962
1,206 Expert 1GB
Is it that you don't know how to write the php code to loop through your points and plot several markers or that you are being restricted by the google api to only one marker?
Jan 18 '11 #2
194 100+
second one is my problem i.e. restricted by the google api to only one marker. cuz addresses will be in database and i know how to loop through them, but this google api is allowing only one address to be marked. please guide me how i can add multiple markers?
Jan 18 '11 #3
1,206 Expert 1GB
You add another marker the same way you added the first one.
Expand|Select|Wrap|Line Numbers
  1. var marker = new google.maps.Marker({
  2.   position: new google.maps.LatLng+results[0].geometry.location, 
  3.   map: map, 
  4.               position: results[0].geometry.location,
  5.   title:"Hello World!"});  
Swap out the position for a new one.
Jan 18 '11 #4
194 100+
i added first market by providing lat/lng values using street address. as i already mentioned addresses are stored into the database. this API is allowing to run only once. as when i tried to run it under PHP/MySQL query its giving me error of "Over Query Limit". Markers will be added using lat/lng values here im confused what is the best way to do it.

Which Google Map API will give me the solution for it?
Jan 19 '11 #5
1,206 Expert 1GB
I'm sorry I really don't know the ins and outs of the Google Maps API. This question isn't PHP specific either.

Now you never mentioned the "Over Query Limit" at the start of all this. I googled it and there is a limit to how many requests you can make using the geocoding API.

I suggest you read this : http://code.google.com/apis/maps/doc...ion/geocoding/
Jan 19 '11 #6
194 100+
im sorry too :). I think i got the solution with a class available at phpclasses. but still i have some issue which i already have posted at this forum "How to insert an array into an array?".

thank you.
Jan 19 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by christopher_board | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.