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

  • Home
  • SEARCH
  • 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 9127171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:13:19+00:00 2026-06-17T07:13:19+00:00

I am trying to do node+geo-stuff to retrieve all locations from given lat,long and

  • 0

I am trying to do node+geo-stuff to retrieve all locations from given lat,long and radius
for that calculation, i am trying below stuff, but it is resulting in NaN.

similar code is working fine in php,python, but could not figure it out what i am doing wrong here.

ref : http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL

PS 1: using nodejs for this calculation as it needs to calculate on server side.
PS 2: even variable name looks like php variable, it is js.

$cat file.js

var log =console.log;
var cos=Math.cos;
var sin=Math.sin;

function rad2deg(x){ log("rad2deg:", x,180*x/Math.pi);return (180*x/Math.pi);}
function deg2rad(x){ log("deg2rad:",x,x*Math.pi/180);return (x*Math.pi/180);}

function getNearPoint($lat,$lng,$rad){

  console.log("Debug1",$lat,$lng);
  $R = 6371;  // earth's radius, km
  // first-cut bounding box (in degrees)
  $maxLat = $lat + rad2deg($rad/$R);
  $minLat = $lat - rad2deg($rad/$R);
  console.log("Debug2",$lat,$lng);
  // compensate for degrees lnggitude getting smaller with increasing latitude
  $maxlng = $lng + rad2deg($rad/$R/cos(deg2rad($lat)));
  $minlng = $lng - rad2deg($rad/$R/cos(deg2rad($lat)));

  console.log("Debug3",$lat,$lng);
  // convert origin of filter circle to radians
  $lat = deg2rad($lat);
  $lng = deg2rad($lng);

  console.log("Debug4",$lat,$lng);

//Build database query and do rest of the stuff
}

getNearPoint(19.1947659,72.8768400,50);

Here is the output.

$ node file.js

Debug1 19.1947659 72.87684
rad2deg: 0.007848061528802385 NaN
rad2deg: 0.007848061528802385 NaN
Debug2 19.1947659 72.87684
deg2rad: 19.1947659 NaN
rad2deg: NaN NaN
deg2rad: 19.1947659 NaN
rad2deg: NaN NaN
Debug3 19.1947659 72.87684
deg2rad: 19.1947659 NaN
deg2rad: 72.87684 NaN
Debug4 NaN NaN
  • 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-17T07:13:20+00:00Added an answer on June 17, 2026 at 7:13 am

    There is no such constant as Math.pi. You probably want to use Math.PI (uppercase) instead. 🙂

    Math.pi is undefined and therefore will eventually just return NaN.

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

Sidebar

Related Questions

I'm trying to upgrade my Node application from 0.4 to 0.6 along with all
I'm trying to use Node.js to create a zip file from an existing folder,
With Node I am trying to collect user data from an LDAP server and
I am trying to limit a node.js application from using to much memory and
I am trying Node.js to get all the titles of this page: https://www.odesk.com/jobs/braintree I
I'm trying to use node_load to pass php variables (as variables!) from one node
When I was trying to copy node from one treeview to another, I got
So I've been trying to get node installed all day. I've reinstalled Xcode, installed
I'm trying to install Node on my CentOS server but it's giving me below
I am messing around in Node.js trying to replicate that simple chat server that

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.