简体   繁体   中英

passing multiple latitude and longitude in to google maps from servlet to jsp

I have set of datas in my database which includes latitudes and longitudes of certain places, I want to calculate the distance of the user and detect places within 5km and pass only those latitudes and longitudes to jsp page and get the google map spotted accordingly.

I had done almost all calculations but I cant pass those certain latitudes and longitudes from servlet to jsp. Could some one guide me.

Here is my servlet code.

for (MapClass coffemap : mms)
  {
    double latt1=Double.parseDouble(searchlat);
    double long1=Double.parseDouble(searchlon);
    double latt2=Double.parseDouble(coffemap.getLati());
    double long2=Double.parseDouble(coffemap.getLongi());
    double theta = long1-long2;
    double dist = Math.sin(deg2rad(latt1)) * Math.sin(deg2rad(latt2)) +   Math.cos(deg2rad(latt1)) * Math.cos(deg2rad(latt2)) * Math.cos(deg2rad(theta));
    dist = Math.acos(dist);
    dist = rad2deg(dist);
     dist = dist * 60 * 1.1515;
     double round=Math.floor(dist * 100) / 100;
    if(round<=5){
    System.out.println(coffemap.getCity() +"Distance: "+round); 
     //how to store only these latitudes and longitudes and pass it to jsp page
    }

Jsp page

<script type="text/javascript">
function load(){

    var searchlat='<%= (String) request.getParameter("lat") %>';//how to get those multiple latitudes
    var searchlon='<%= (String) request.getParameter("lon") %>';// how to get those multiple longitudes
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(searchlat,searchlon), 13);
mapTypeId: google.maps.MapTypeId.ROADMAP;

var point = new GLatLng(searchlat,searchlon);
map.setCenter(point, 14);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}

</script>

从javascript发出ajax请求,该javascript调用servlet ...例如您重新运行json的Java代码

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM