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

  php

Q(Question):

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.


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function codeAddress() {
var address = 'Sydney, NSW';
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
initialize();
map.setCenter(results[0].geometry.location);
/* var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});*/
var marker = new google.maps.Marker({
position: new google.maps.LatLng+results[0].geometry.location,
map: map,
position: results[0].geometry.location,
title:"Hello World!"});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
</head>
<body onload="initialize();codeAddress();">
<div id="map_canvas" style="height:90%"></div>
</body>
</html>

Please tell me how i can add multiple pin points to google map. I dont wana use static map.

Thanking you.

Faisal

A(Answer):

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?

A(Answer):

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?

A(Answer):

You add another marker the same way you added the first one.


var marker = new google.maps.Marker({
position: new google.maps.LatLng+results[0].geometry.location,
map: map,
position: results[0].geometry.location,
title:"Hello World!"});

Swap out the position for a new one.

A(Answer):

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?

A(Answer):

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/

A(Answer):

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.

LEAVE A COMMENT