By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

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

100+
P: 194
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.   }
  22.  
  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.         });*/
  33.  
  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();">
  47.  
  48. <div id="map_canvas" style="height:90%"></div>
  49. </body>
  50. </html>
  51.  
Please tell me how i can add multiple pin points to google map. I dont wana use static map.

Thanking you.

Faisal
Jan 17 '11 #1
Share this Question
Share on Google+
6 Replies


JKing
Expert 100+
P: 1,206
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

100+
P: 194
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

JKing
Expert 100+
P: 1,206
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!"});  
  6.  
Swap out the position for a new one.
Jan 18 '11 #4

100+
P: 194
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

JKing
Expert 100+
P: 1,206
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

100+
P: 194
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.