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 7545581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:58:03+00:00 2026-05-30T08:58:03+00:00

Currently I have a page displaying 3 Google Maps that are generated by JavaScript,

  • 0

Currently I have a page displaying 3 Google Maps that are generated by JavaScript, these are based on a geocode that is hard coded into the JavaScript.

I now have set the geocodes within an XML file and using a PHP function to call the geocode from the XML into a array. But I’m unsure on how to go about parsing this from the array into the JavaScript.

Here is my JavaScript.

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?   sensor=true&libraries=places"></script>
<script type="text/javascript">

function initMap(mapObj, lat, lng) {
    var latLng = new google.maps.LatLng(lat, lng);
    var mapInstance = new google.maps.Map(mapObj, {
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: latLng,
        zoom: 11
    });
    var infowindow = new google.maps.InfoWindow();
    var service = new google.maps.places.PlacesService(mapInstance);

    function createMarker (place) {
        var marker = new google.maps.Marker({
            animation: google.maps.Animation.DROP,
            map: mapInstance,
            position: place.geometry.location
        });
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent(place.name);
            infowindow.open(mapInstance, this);
        });        
    }

    function searchCallback(results, status) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {
            for (var i = 0; i < results.length; i++) {
                createMarker(results[i]);
            }
        }
    }

    service.search({ location: latLng, radius: 5000 }, searchCallback);
}


function initialize() {
    var ndx = 0;
    function calInitMap(lat, lng) {
        initMap(document.getElementById('map'+ndx), lat, lng);
        ndx++;
    }
    calInitMap(51.5069999695, -0.142489999533);
    calInitMap(40.79445,-74.01558);
    calInitMap(48.858001709, 2.29460000992);
}

google.maps.event.addDomListener(window, 'load', initialize);
 </script>
 <noscript>JavaScript not detected! Verify that JavaScript support is enabled in your browser, or upgrade to a newer JavaScript-capable web browser and try again.</noscript>

<div id="map0" style="position:absolute; width: 290px; height: 300px;"></div>
<div id="map1" style="position:absolute; left:492px; width: 288px; height: 300px;"></div>
<div id="map2" style="position:absolute; left:788px; width: 290px; height: 300px;"></div>

Here is the PHP function I’m using to call in the geocode from the XML file.

 function getGeocode() {

try {
    $xml = new SimpleXmlElement(file_get_contents('config/cityConfig.xml'));
} catch (Exception $e) {
    echo 'Caught exception: An error has occured. Unable to get cityConfig.xml';
}

$geoSource = array();
foreach ($xml->city as $city) {
    $geo = (string) $city->geocode;
    array_push($geoSource, $geo);
}

return $geoSource;
 }
 ?>

I have thought about using calInitMap($geocodeSource[0]);, or would it be better to use a JavaScript function to access the XML file? Any suggestions?

  • 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-30T08:58:04+00:00Added an answer on May 30, 2026 at 8:58 am

    You may store the array as a variable in JS:

    var geocodes=<?php echo json_encode(getGeocode());?>
    

    …no need for parsing on JS-side.

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

Sidebar

Related Questions

I'm displaying 10 records per page. The variables I have currently that I'm working
currently: i have a page view that is displaying all content that is flagged
I currently have an advanced search page that searches a number of fields in
I currently have a product view page that contains an MVCContrib HTML Grid with
I currently have a web form aspx page that calls RegisterClientScriptBlock. This sends down
Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should
I have a page that is currently using the datetime microformat to display a
I have some the page elements split into separate visual blocks. I am currently
Let's say I have a web page that currently accepts a single ID value
i have created an application in jquery and google maps javascript v3 , in

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.