Calculate distance by longitude and latitude : <p>I have a code for calculate distance by latitude and longitude selected form a database, the executed result returns mistakes, it shows: </p>

<p>[53, 190] The left expression is not an arithmetic expression.</p>

<p>[193, 256] The right expression is not an arithmetic expression</p>

<p>Here is my code:</p>

<pre><code>@GET
@Path("returnNearbyFriends/{studentid}/{longitude}/{latitude}")
@Produces({"application/json"})
public JsonArray returnNearbyFriends(@PathParam("studentid") Integer studentid, @PathParam("longitude") Double longitude, @PathParam("latitude") Double latitude) {
    TypedQuery q = em.createQuery("select distinct(l.studentid.studentid), l.date, (ACOS(SIN((:latitude * 3.1415) / 180 ) *SIN((l.latitude * 3.1415) / 180 ) +COS((:latitude * 3.1415) / 180 ) * COS((l.latitude) * 3.1415) / 180 ) *COS((:longitude * 3.1415) / 180 - (l.longitude * 3.1415) / 180) * 6380) as Distance "
            + "from Location l "
            + "where l.date in (select max(l.date) FROM Location l group by l.studentid) "
            + "order by l.date;", Location.class);
    q.setParameter("studentid", studentid);
    q.setParameter("longitude", longitude);
    q.setParameter("latitude", latitude);
    List&lt;Object[]&gt; list = q.getResultList();
    JsonArrayBuilder builder = Json.createArrayBuilder();
    for (Object[] obj : list){
        String sid = (String) obj[0];
        String ldate = (String) obj[1];
        String distance = (String) obj[2];
        JsonObject jsObject = Json.createObjectBuilder()
                .add("StudentID", sid)
                .add("LocationDate", ldate)
                .add("Distance", distance)
                .build();
        builder.add(jsObject);             
    }
    JsonArray result = builder.build();
    return result;
}
</code></pre>

<p>Who can help me to solve the problem?</p>
