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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:50:41+00:00 2026-06-17T18:50:41+00:00

This is just a thought, it might not be feasible, googled it and can’t

  • 0

This is just a thought, it might not be feasible, googled it and can’t come up with anything, I don’t think I’m searching for it correctly, I don’t really know how to word the problem, so I’ll explain it:

So I pull my location data from a table like this in PHP:

$result = $Connect->query($sql);
$i = rand(00000000, 99999999);
while($locationData = $result->fetch_assoc()){
    $locationName = $locationData['locationName'];
    $locationStreetAndHouse = $locationData['locationStreetNameAndNumber'];
    $locationState = $locationData['locationState'];
    $locationLat = $locationData['locationLatitude'];
    $locationLon = $locationData['locationLongitude'];
    $returnThis .= 'var latLonV'.$i.' = new    google.maps.LatLng('.$locationLat.','.$locationLon.')
var marker'.$i.' = new google.maps.Marker({
position: latLonV'.$i.',
map: map,
title: "'.$locationName.'"
});';
$i++;
}
$Connect->close();  

Then I Send that back to my JS like this:

$JSONData = array("true", $returnThis); 
echo json_encode($JSONData); 

Then in JS I do this:

success:function (recievedData) {
  if (recievedData[0] == 'true') {
    initializeMap(recievedData[1]);
  }

}


function initializeMap(markerVar) {
    var myLatlng = new google.maps.LatLng(40.915117, -74.072465);
    var mapOptions = {
        zoom: 16,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'THIS IS ME!'
    });

    markerVar;
}

});

Of course the map will come up without an issue and the first location comes up, but how do I take the JS data stored within the markerVar and use it?

I hope I’m explaining it correctly, sorry if it’s a stupid way of doing it, I’m open to different way of doing it as well.

  • 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-06-17T18:50:42+00:00Added an answer on June 17, 2026 at 6:50 pm

    Currently you create a string containing JavaScript code. Afterwards you encode this string via JSON, transfer it the client.

    But here you do not execute it, but try to pass it on as a string.

    A better approach would be to create an array of objects in PHP like this:

    $returnVal = array();
    while( /*...*/ ) {
      /* your init code */
    
      $returnVal[] = array( 'lat' => $locationLat, 'lon' => $locationLon /* etc */ );
    }
    
    echo json_encode( array( true, $returnVal ) );
    

    On the client you can then use these values to generate all your markers dynamically:

    function initializeMap(markerVar) {
      /* your init code */
    
      var marker = [], latLonV;
      for( var i=markerVar.length; i--; ) {
        // create the latlon object
        latLonV = new google.maps.LatLng( markerVar[i]['lat'], markerVar[i]['lon'] )
    
        // set the marker
        marker.push(new google.maps.Marker({
                             position: latLonV,
                             map: map,
                             title: markerVar[i]['title']
                           }));
      }
    }
    

    Depending on your needs, you may want to wish to insert the marker and latLonV objects into an separate array to get a hold of them later on.

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

Sidebar

Related Questions

This might be c# basics 101, but I just thought if I don't ask
i'm not particularly new at python but i just thought there might be a
I probably just haven't thought this through, or perhaps I'm simply unaware of an
I thought I had this figured out but it turns out I'm just deleting
This just saves time. Since I already have a web applciation. I can just
I fear this just may not be possible, but I'm trying to create a
I assume this just returns an int. Is there anything else going on I
This question might not belong here, and since this is related to HTML and
Well, i was trying to reach a solution and i thought this might work:
Just wondering if you had any thoughts on this problem. I want to make

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.