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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:07:38+00:00 2026-06-10T17:07:38+00:00

I am trying to use the geocoding service with the google maps to display

  • 0

I am trying to use the geocoding service with the google maps to display markers for nearby places. I am not getting well sorted results, that is they appear to be random and not close to the zipcode provided. I am using a radius of 50000. The code is as given below.

   latlng = new google.maps.LatLng(lat,longitude);
var myOptions = {
  zoom: zoom,
  center: latlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};

map = new google.maps.Map(document.getElementById("map"), myOptions);


//alert("Radius:"+radius_hidden);
var requestsearch = {
    location: latlng,
    radius: radius_hidden,
    name: searchname,
    types: ['store']
};
// keyword: searchname,//name: searchname, to get like pages and name to get exact
service = new google.maps.places.PlacesService(map);
//service.textSearch(requestsearch, callback);
service.search(requestsearch, callback);

if(map != null) {
    google.maps.event.addListener(map, 'drag', function(event) {
        calculateCenter();  
    });
}
          }
       google.maps.event.addDomListener(window, 'load', initialize);


         google.maps.event.addDomListener(window, 'resize', function() {
          map.setCenter(center);
           //google.maps.event.trigger(map, 'resize');
        });
          function calculateCenter() {
        var latlngbounds = new google.maps.LatLngBounds();

        for (var i = 0 ; i < markersArray.length ; i++) {
     latlngbounds.extend(markersArray[i].getPosition());
   }

       //map.setCenter(latlngbounds.getCenter(), map.getBoundsZoomLevel(latlngbounds));
     map.setCenter(latlngbounds.getCenter());
     map.fitBounds(latlngbounds);
        center = map.getCenter();
               }

       function callback(results, status)
         {
var listing='<table width="100%" border="1">';
var num=5;
markersArray = new Array();
if (status == google.maps.places.PlacesServiceStatus.OK) 
{
  for (var i = 0; i < results.length; i++) 
  {
    var pincode='';
    var address='';
    geocoder = new google.maps.Geocoder();
    geocoder.geocode({
      'address': results[i].vicinity,
      'partialmatch': true},function(resultsp, status)
      {
        if (status == 'OK' && resultsp.length > 0) 
        {
            address=resultsp[0].formatted_address;
            var len=resultsp[0].address_components.length-1;
            var res=resultsp[0].address_components[len].short_name;
            if(res!=undefined)
            {
                //address+="<br>Pincode:"+res.toString();
            }
            //listing+='<tr><td>Zip Code: '+res.toString()+'</td></tr>';
        } 
    });

    marker = new google.maps.Marker({
        position: results[i].geometry.location,
        title: results[i].name,
        zIndex: 2,
        icon: gicons["blue"]
    });
            markersArray.push(marker);
    calculateCenter();
    listing+='<tr><td>';

    var address_link=results[i].vicinity.replace(" ","+");
    if(i==0)
    {
        listing+='<table id="div5" width="100%" >'; 
    }
    else if(i%5==0)
    {
        num+=5;
        listing+='<table id="div'+num+'" style="display:none;" width="100%">';  
    }
    //'+results[i].name+'


 listing +='<tr id="searchadd"><td ><input type="hidden" value="'+results[i].name+'" name="end'+i+'" id="end'+i+'"></td></tr><tr><td style="word-wrap: break-word;" onmouseout="markersArray['+i+'].setIcon(gicons.blue)" onmouseover="markersArray['+i+'].setIcon(gicons.yellow)" class="" id="item-'+i+'">'+getaddress(results[i].vicinity)+'<div id="spacer" style="width:120px;height:1px;float:left;"></div><a   style="width:100px;height: 20px;" class="sty-hyperlink" target="_blank" href="https://maps.google.com/maps?daddr='+address_link+'"><b><?php echo getFieldFromDB('user_config','DirectionText'); ?></b></a><br></td></tr>';

        if(i ==(results.length-1))
        {
            listing+='</table>';
            listing+='<span id="largerwindowlink"><br><a  target="_blank" class="sty-action-buttn" href="<?php echo $finalURL; ?>"><?php echo trim(getFieldFromDB('user_config','ActionButtonText')); ?></a></span>';
        }
        else if(i>0 &&(i+1)%5==0)
        {
            listing+='<tr><td align="right"><a class="sty-hyperlink" style="width:100px;height: 20px;" href="javascript:void(0);" onclick="javascript:show_hide_table('+num+');" ><b><?php echo getFieldFromDB('user_config','MoreResultText'); ?></b></a></td></tr></table>';
        }
        listing+='</td></tr>';
      }
      showOverlays(5);
      listing +='</table>';
      if(results.length<=0)
      {
            listing='<br><br><span style="color:green;">Sorry! No stores found.<br>Please try another franchise name</span><br><br>';
      }
    }
    else
    {
        listing='<br><br><span style="color:green;">Sorry! No stores found.<br>Please try another franchise name</span><br><br>';
    }
    document.getElementById("listingAddress").innerHTML=listing;
}
function showOverlays(no) 
{
    if (markersArray) 
    {
        for (i in markersArray) 
        { 
            if(i<no && i>=no-5)
                markersArray[i].setMap(map);
        }
    }
}
function clearOverlays() 
{
    if (markersArray) 
    {
        for (i in markersArray) 
        {
                markersArray[i].setMap(null);
        }
    }
}

I want to have the results in correct order, that is the closer ones first and then the rest.

  • 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-10T17:07:40+00:00Added an answer on June 10, 2026 at 5:07 pm

    If you want the places results ordered by distance, you need to tell the API to do that.

    https://developers.google.com/maps/documentation/javascript/reference#RankBy

    1. Example

    2. Example

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

Sidebar

Related Questions

I'm trying to cache Google Maps geocoding results in my database (mongoDB). So that
I am trying to do some basic geocoding using the google maps API and
I am trying to use the Google Geocoding API to get the latitude and
I'm trying to use the Google maps JavaScript API to draw a line between
I've been trying to get a json response from google's geocoding service. I'm using
I am trying use Google Maps for my work; I have downloaded an example
trying to use hibernate with my web app and getting following exception: Initial SessionFactory
I'm trying to use the geocoding code from here in my ASP.NET MVC 2
I use the StreamReader class to obtain XML for my GeoCoding process from Google.
I've seen many posts about the Google Geocoding API, described here: http://code.google.com/apis/maps/documentation/geocoding/ but none

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.