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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:44:18+00:00 2026-06-14T09:44:18+00:00

I am using google maps in my real estate site for displaying projects in

  • 0

I am using google maps in my real estate site for displaying projects in different location

The locations are displayed in green markers as in below link

Map Link

var markers = new Array();
var i;


function DrawMap(locations)
{   
  var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 10,
              center: new google.maps.LatLng(-33.92, 151.25),
              mapTypeId: google.maps.MapTypeId.ROADMAP
        });

var flagIcon_front = new google.maps.MarkerImage("images/marker.png");

var flagIcon_shadow = new google.maps.MarkerImage("images/marker_shadow.png")
flagIcon_shadow.size = new google.maps.Size(105, 53);
flagIcon_shadow.anchor = new google.maps.Point(20, 52);         
var boxText = document.createElement("div");
boxText.style.cssText = "border: 1px solid black; margin-top: 8px; padding: 5px; display:block; ";

var myOptions = {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-261, -268)
,zIndex: null
,boxStyle: { 
background: "url('images/metro-plot-bg-1.png') no-repeat -286px -1361px"
,opacity: 1
,width: "393px"
,height: "233px"
}
,closeBoxMargin: "11px 32px 2px 2px"
,closeBoxURL: "images/close_small.png"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false              
};  
var infowindow = new google.maps.InfoWindow();  
var marker;
for (i = 0; i < locations.length; i++) 
{  
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
icon: flagIcon_front,
shadow: flagIcon_shadow,         
map: map
});       
markers.push(marker);
}
for(i=0;i<locations.length;i++) 
{  
 marker1 = markers[i];
google.maps.event.addListener(marker1, 'click', (function(marker1, i) {
return function() {
          //infowindow.setContent(locations[i][0]);
          //infowindow.open(map, marker);
          ib.setContent(locations[i][0]);
          ib.open(map, marker1);
          }
      })(marker, i));
 //marker.setMap(null);
var ib = new InfoBox(myOptions);
//ib.open(map, marker);
}   
}

var locations = [
                              ['<div class="map_view"></div>', -33.890542, 151.274856, 4],
                              ['<div class="map_view"></div>', -33.923036, 151.259052, 5],
                              ['<div class="map_view"></div>', -34.028249, 151.157507, 3],
                              ['<div class="map_view"></div>', -33.80010128657071, 151.28747820854187, 2],
                              ['<div class="map_view"></div>', -33.950198, 151.259302, 1]
                            ];



                            $('document').ready(function(e) {
                               DrawMap(locations);
                            });

The DrawMap() function above takes latitude and longitude as parameter

 var locations = [
                              ['<div class="map_view"></div>', -33.890542, 151.274856, 4],
                              ['<div class="map_view"></div>', -33.923036, 151.259052, 5],
                              ['<div class="map_view"></div>', -34.028249, 151.157507, 3],
                              ['<div class="map_view"></div>', -33.80010128657071, 151.28747820854187, 2],
                              ['<div class="map_view"></div>', -33.950198, 151.259302, 1]
                            ];



                            $('document').ready(function(e) {
                               DrawMap(locations);
                            });

The map is working fine when the page loads first time. All the markers are displayed the right way.But when i populate the map by supplying latitude and longitude as parameter which I got as responseText for ajax call on button click the map is displaying markers grouped at one place.

The script for ajax call is as below

function getLocations()
{
  for(i=0;i<locations.length;i++) 
  {
    markers[i].setMap(null);
  }
  url = 'map.php';      
  $.post(
  url,
  {
   "act" : "getLocations"   
  },
  function(responseText){                                       
   DrawMap(responseText);
  },
  "html"
);
}

The working copy is uploaded in the following link

Map Link

Click the button at bottom for getting latitude and longitude as response text from ajax request

Please let me know which my markers are not redrawn to new location

Thanks in advance

  • 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-14T09:44:20+00:00Added an answer on June 14, 2026 at 9:44 am

    In the button click, you are calling a $.post, but then sending the responseText to the DrawMap method. DrawMap is expecting a javascript array, not JSON text, so you’ll probably want to call that method like so:

    function(responseText) {
        DrawMap($.parseJSON(responseText));
    }
    

    Also, what you’re passing from the server isn’t JSON that jQuery can parse. To wit:

    jQuery.parseJSON docs:
        ...
        {'test': 1} ('test' is using single quotes instead of double quotes).
        ...
    

    You’re JSON code looks like this:

    [
        ['<div class="map_view"></div>', -33.790542, 151.274856, 4],
        ['<div class="map_view"></div>', -33.983036, 151.259052, 5],
        ['<div class="map_view"></div>', -34.128249, 151.157507, 3],
        ['<div class="map_view"></div>', -33.85010128657071, 151.28747820854187, 2],
        ['<div class="map_view"></div>', -33.900198, 151.259302, 1]     
    ]
    

    Try changing the quotes around, like this:

    [
        ["<div class='map_view'></div>", -33.790542, 151.274856, 4],
        ["<div class='map_view'></div>", -33.983036, 151.259052, 5],
        ["<div class='map_view'></div>", -34.128249, 151.157507, 3],
        ["<div class='map_view'></div>", -33.85010128657071, 151.28747820854187, 2],
        ["<div class='map_view'></div>", -33.900198, 151.259302, 1]     
    ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Google Maps in order to display current user location. While using
I'm using Google Maps' API and added a few markers in a map. Each
I am using Google Maps for finding the location on a provided address. I
I am using Google Maps v3 to geocode addresses on a site and it
I've recently started using Google Maps API v3. I need to plot some locations
I'm using Google Maps JavaScript API V2 to mark locations saved in an array.
Using Google Maps API how to determine the driving distance between two locations? Platform
Using google maps I would like to retrieve and display all locations withing a
I'm using Google Maps v3. I've already suppressed markers to display my own on
I'm using Google Maps with Flex 3. I'm having problems clearing markers. Users can

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.