Rectangle 27 2

1) You need a PHP loop to iterate the result set from the query, and then generate a javascript array of addresses.

var address = '<?php echo $address.', '.$city.', '.$state; ?>';
var addresses = [];
<?php while ($row = mysql_fetch_assoc($my_query)) { ?>
addresses.push(<?php echo '"' . $row['address'].', '.$row['city'].', '.$row['state'] . '"'; ?>);
<?php } ?>

2) Wrap a javascript loop around your geocoder.geocode function call, to iterate over the addresses array you just generated.

for(i in addresses) {
    var address = addresses[i];
    geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map, 
                position: results[0].geometry.location
            });
        } else {
            // alert("Geocode was not successful for the following reason: " + status);
        }
    });

Thanks for the reply. It's way past bedtime, but I can't wait to try this in the morning. I'll let you know how it goes.

I tried this solution but just couldn't get it to work. Instead of showing all the listings and only mapping the first listing, now the page shows only the first listings and the map doesn't show at all.

php - Google Maps (api v3) - Loop through mysql query results to geoco...

php mysql google-maps google-maps-api-3
Rectangle 27 0

It seems to be a bug in Geocode API. I have reported a bug to google web services.

php - Google Geocode API returns same result for different locations -...

php android ios google-api google-geocoding-api
Rectangle 27 0

"You need to replace & in the address argument by its URL-encoding %26"

{
   "results" : [],
   "status" : "ZERO_RESULTS"
}
{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "2301",
               "short_name" : "2301",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "East Fowler Avenue",
... and so on ...
%26
place = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef) place,                                                                                      NULL, CFSTR("!*'();:@&=+$,/?%#[]\" "),                                                                                      kCFStringEncodingUTF8));

I'd have to look at Google API docs to see what the requirements are and escape only what they say to escape.

php - Google geocode API not returning result for certain locations - ...

php android ios google-api google-geocoding-api
Rectangle 27 0

You need to use the Google Geocode API to reverse geocode your address to obtain the co-ordinate which can then be used to display the results on the map. For example for my address I post to address parameters as given in the url below

http://maps.googleapis.com/maps/api/geocode/json?address=154+Metro+Central+Heights+London+UK&sensor=true

Co-ordinates can be obtained from the resulting JSON as shown below

"geometry": {
      "location": {
        "lat": 51.5001524,
        "lng": -0.1262362
      }
<?php

$address = $_GET['address'];
$address=str_replace(" ","+",$address);
if ($address) {
    $json = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.$address.
    '&sensor=true');
    echo $json;
}

?>

The Javascript can be found here. The critical code which parses the JSON is given below

$.getJSON("getjson.php?address="+address,
        function(data){
            lat=data.results[0].geometry.location.lat;
            lng=data.results[0].geometry.location.lng;
                        //.... more map initialization code
                 }
);

I had already set up a working example for your previous question here which should help you understand how to generate markers on the map. Let me know in case you need further clarification.

Ok, but what if I need to use XML instead of JSON? At this moment when I put "maps.googleapis.com/maps/api/geocode/json? anywhere Opera popups download window and asks where to download this "json" file...

Each browser has a different way of handling different file formats. If you intend to see the JSON format try opening it in firefox or chrome. If you need XML you need to replace json with xml like this http://maps.googleapis.com/maps/api/geocode/xml?address=your+address&sensor=true. I've shown you the json format because it easier to parse this either using plain javascript or jQuery.

Again please note that in Safari, XML is rendered differently as opposed to say IE. If you need to see the raw XML document in Safari you need to view the source. Do not how it is with Opera.

Thanks, but as I said before vertyhing with xml works fine, but have no idea how to parse :(

php - Google Geocode API result displaying on map? - Stack Overflow

php google-maps google-maps-api-3
Rectangle 27 0

1) You need a PHP loop to iterate the result set from the query, and then generate a javascript array of addresses.

var address = '<?php echo $address.', '.$city.', '.$state; ?>';
var addresses = [];
<?php while ($row = mysql_fetch_assoc($my_query)) { ?>
addresses.push(<?php echo '"' . $row['address'].', '.$row['city'].', '.$row['state'] . '"'; ?>);
<?php } ?>

2) Wrap a javascript loop around your geocoder.geocode function call, to iterate over the addresses array you just generated.

for(i in addresses) {
    var address = addresses[i];
    geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map, 
                position: results[0].geometry.location
            });
        } else {
            // alert("Geocode was not successful for the following reason: " + status);
        }
    });

Thanks for the reply. It's way past bedtime, but I can't wait to try this in the morning. I'll let you know how it goes.

I tried this solution but just couldn't get it to work. Instead of showing all the listings and only mapping the first listing, now the page shows only the first listings and the map doesn't show at all.

php - Google Maps (api v3) - Loop through mysql query results to geoco...

php mysql google-maps google-maps-api-3