title: How to verify whether a point lies within a sector formed by the geocoordinates
body: <p>I have written a Java code that verifies whether a point lies within a sector of a circle defined radius. Both the point and the circle centre are represented in terms of latitude and longitude.</p>
  
  <p>The Java code is as follows-</p>
  
  <pre><code>public boolean isPointWithin(float centreLat,float centreLong,float pointLat,float pointLong,int maxDistance)
      {                               
          float adjFactor=0.0f;
          double angleRange,bisectorIVector,bisectorJVector,IVector,JVector,VectorLength,dotProduct,EnodeBAngle,
          latScale=0.0,longScale=0.0,distance,lower,upper,count,adjustmentFactor=0.0,jVector,dist1,dist2;
          dist1=Math.pow(centreLat-pointLat, 2)+Math.pow(centreLong-pointLong, 2);
          dist2=Math.pow(centreLat-pointLat, 2)+Math.pow(360-(Math.abs(centreLong)+Math.abs(pointLong)), 2);
          if(dist1&gt;dist2)
          {
              adjFactor=360-(Math.abs(pointLong)+Math.abs(centreLong));
              if(centreLong&gt;0)
                  pointLong=(centreLong+adjFactor);
              else
                  pointLong=(centreLong-adjFactor);
          }
          latScale=(111132.954-(559.822*Math.cos(2*Math.toRadians(pointLat)))+1.175*Math.cos(4*Math.toRadians(pointLat)))/1000;
  
          angleRange=Math.toRadians(sectorAngle);
  
          bisectorIVector=maxDistance*Precision.round(Math.sin(Math.toRadians(sectorDirection)),8);
          bisectorJVector=maxDistance*Precision.round(Math.cos(Math.toRadians(sectorDirection)),8);
  
          IVector=pointLong-centreLong; 
          JVector=pointLat-centreLat;
  
          if(pointLong&lt;centreLong)
          {
              lower=pointLong;
              upper=centreLong;
          }
          else
          {
              upper=pointLong;
              lower=centreLong;
          }
          count=lower;
          while(Math.ceil(count)&lt;Math.floor(upper))
          {
              jVector=((JVector/IVector)*(count-centreLong))+centreLat;
              longScale+=Math.cos(Math.toRadians(jVector)); 
              count++;
          }
          longScale*=latScale;
          if((upper-lower)&gt;Math.floor((upper-lower)))
          {
              jVector=((JVector/IVector)*(upper-centreLong))+centreLat;
              adjustmentFactor=Math.cos(Math.toRadians(jVector))*latScale*((upper-lower)-Math.floor((upper-lower)));
          }
          longScale+=adjustmentFactor;
  
  
          distance=Math.sqrt(Math.pow(longScale,2) + Math.pow(JVector*latScale,2));
          VectorLength=Math.sqrt(Math.pow(IVector,2) + Math.pow(JVector,2));
          if(VectorLength==0.0)
              return true;
  
          dotProduct=bisectorIVector*IVector+bisectorJVector*JVector;
          EnodeBAngle=Precision.round(Math.acos(dotProduct/(maxDistance*VectorLength)),8);
  
          if(EnodeBAngle&lt;=Precision.round(angleRange/2,8) &amp;&amp; distance&lt;=maxDistance)
              return true;
          else
              return false;
      }
  </code></pre>
  
  <p>Now If the point is within the sector I am trying to mark the point on the sector drawn on map using the google api.</p>
  
  <p>But the problem is that even if my java code return true i.e. point lies within sector still, the corresponding sector plotted on google map shows that the point is outside the sector.</p>
  
  <p>Please help me as to whether did I go wrong? </p>