简体   繁体   English

使用Jsp和servlet使google map指向用户定义的位置

[英]To make a google map point to user defined location using Jsp and servlet

I wish to develop an google map,that takes the input from a form(city,area &Country) and wen i press the submit. 我希望开发一个谷歌地图,它从表单(城市,地区和国家)中获取输入,然后按提交。 ie.,1st JSP page and request is sent to Servlet and Servlet sends response to 2nd JSP page. 即,第一个JSP页面并将请求发送到Servlet,然后Servlet将响应发送到第二个JSP页面。 In 2nd JSP page it should display map and points the location in google map.so how do i do it? 在第二个JSP页面中,它应该显示地图并在google map中指向位置。那我该怎么办?

You just need to get lat/long from the address that you have provided in the 1st JSP by using Geocoder and then pass those lat/long to second JSP. 您只需使用Geocoder从第一个JSP中提供的地址获取经纬度,然后将那些经纬度传递给第二个JSP。 Use below code to initialize map in script: 使用以下代码在脚本中初始化地图:

 var marker = null;
    var map = null;
    var markers = [];
    var markerColorPrefix;
    var infoWindow = new google.maps.InfoWindow(), marker, i;
    function initializeMap()
    {
        var map_canvas = document.getElementById('map_canvas');
        var map_options = {
            //center: myCenter,
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.SATELLITE
        }
        map = new google.maps.Map(map_canvas, map_options)

    }

And use below code to update required location: 并使用以下代码更新所需的位置:

function updateMap(gps)
{
    var latitude = "${recentLocation.latitude}";
    var longitude = "${recentLocation.logitude}";
    var gpsPoint = new google.maps.LatLng(latitude, longitude);
    if(marker != null)
        marker.setMap(null);
    if(map!=null)
        map.setCenter(gpsPoint);
    marker = new google.maps.Marker({
    position:gpsPoint,
    map:map
    });
    markers.push(marker);
}

Define dive in which you want to display Google Map: 定义要在其中显示Google Map的潜水:

<div id="map_canvas"></div>

This will display your location on the map. 这将在地图上显示您的位置。

Hope this will help you. 希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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