Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3216964
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:21:22+00:00 2026-05-17T15:21:22+00:00

I’m trying to display an array of postcodes onto a google map using PHP

  • 0

I’m trying to display an array of postcodes onto a google map using PHP and using the Symfony Framework (1.0)

The main problem I am having, is that there is some text associated with each marker, i.e when you click the marker a popup appears.

The main problem is that the text should point to the correct postcode/marker on the map, but for some reason this doesn’t seem to be the case:

<?php
$addresses = array();
foreach($contents->getResults() as $content):
    $addresses[] = array(
        'postcode'=>sprintf('%s',str_replace(' ','',$content->getPostalCode())),
        'html'=>escape_javascript(get_partial('property/propertyList',array('content'=>$content))),
    );
endforeach;
?>

<?php
echo javascript_tag("
var map;
var localSearch = new GlocalSearch();
var center = false;
var icon = new GIcon();
icon.image = 'http://www.google.com/mapfiles/marker.png';
icon.shadow = 'http://www.google.com/mapfiles/shadow50.png';
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(37, 34);
icon.iconAnchor = new GPoint(10, 34);
var delay = 100;
var bounds = new GLatLngBounds();

var addresses = ".json_encode($addresses).";

var nextAddress = 0;

function theNext() {
    if (nextAddress < addresses.length) {
        var postcode = addresses[nextAddress].postcode;;
        var html = addresses[nextAddress].html

        setTimeout('getAddress(\"'+postcode+'\",\"'+html+'\",theNext)', delay);
        nextAddress++;
    }
}
function getAddress(search, html, next) {
    usePointFromPostcode(search, html);
    next();
}

var geoCount = 0;
function usePointFromPostcode(address, html, callbackFunction) {
    localSearch.setSearchCompleteCallback(null, 
        function() {
            if (localSearch.results[0])
            {   
                geoCount++;

                var resultLat = localSearch.results[0].lat;
                var resultLng = localSearch.results[0].lng;
                var point = new GLatLng(resultLat,resultLng);

                var marker = new GMarker(point);
                GEvent.addListener(marker, 'click', function() {
                    marker.openInfoWindowHtml(html);
                });
                map.addOverlay(marker);
                bounds.extend(point);

                if(geoCount == addresses.length) {
                    setCenterToBounds();
                }
            }else{
                //console.info('Postcode not found!', address);
            }
        }); 

    localSearch.execute(address + ', UK');
}

function placeMarkerAtPoint(point, html)
{
    var marker = new GMarker(point,icon);
    map.addOverlay(marker);
}

function setCenterToBounds()
{
    map.setCenter(bounds.getCenter());
    map.setZoom(map.getBoundsZoomLevel(bounds));
    console.info('zoom',map.getBoundsZoomLevel(bounds));
}

function mapLoad() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById('map'));

        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        theNext();
    }

}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addUnLoadEvent(func) {
    var oldonunload = window.onunload;
    if (typeof window.onunload != 'function') {
      window.onunload = func;
    } else {
      window.onunload = function() {
        oldonunload();
        func();
      }
    }
}
addLoadEvent(mapLoad);
addUnLoadEvent(GUnload);
")
?>

It only happens on some of the markers though. It is like it finds the postcode, puts the marker on, but then displays the wrong details for it

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:21:23+00:00Added an answer on May 17, 2026 at 3:21 pm

    Ok, so it seems that the data coming back from Google, seemed to come back in the wrong order.

    Changing the var delay = 100 to var delay = 200 seemed to fix this

    Even though it made the map load a little bit slower

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.