小编use*_*263的帖子

SockJS无法创建/连接到Spring WebSocket

我正在学习Spring WebSocket。我已经成功运行了此Spring WebSocket教程。现在,我试图按原样将其合并到我现有的Spring MVC应用程序中。当我从Chrome浏览器运行它时,在其开发控制台中看到以下错误。

Chrome控制台

Opening Web Socket...
GET http://localhost:8080/MyAppName/api/gs-guide-websocket/info?t=1497735312528 500 (Internal Server Error) -- abstract-xhr.js:132
Whoops! Lost connection to http://localhost:8080/MyAppName/api/gs-guide-websocket -- stomp.min.js:8 
Run Code Online (Sandbox Code Playgroud)

服务器端错误

javax.servlet.ServletException: Could not resolve view with name '/MyAppName/api/gs-guide-websocket/info' in servlet with name 'MyAppName'
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1262)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
Run Code Online (Sandbox Code Playgroud)

客户端

function connect() {
    var socket = new SockJS('/MyAppName/api/gs-guide-websocket');
    stompClient = Stomp.over(socket);
    stompClient.connect({}, function (frame) {
        setConnected(true);
        console.log('Connected: ' + frame);
        stompClient.subscribe('/topic/greetings', function (greeting) {
            showGreeting(JSON.parse(greeting.body).content);
        });
    });
}
Run Code Online (Sandbox Code Playgroud)

服务器端

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig …
Run Code Online (Sandbox Code Playgroud)

spring stomp spring-mvc sockjs spring-websocket

5
推荐指数
1
解决办法
2179
查看次数

计算由lat表示的两点之间的距离,长达15英尺精度

我已将公式转换为此处提供的Java .但准确性是一个问题.我们正在使用GPS坐标.

我们正在使用iPhone提供的GPS位置,精度高达10小时.

/*
 * Latitude and Longitude are in Degree
 * Unit Of Measure : 1 = Feet,2 = Kilometer,3 = Miles
 */
//TODO 3 Change Unit of Measure and DISTANCE_IN_FEET constants to Enum
public static Double calculateDistance(double latitudeA,double longitudeA,double latitudeB,double longitudeB,short unitOfMeasure){

    Double distance;

    distance = DISTANCE_IN_FEET * 
               Math.acos(       

                               Math.cos(Math.toRadians(latitudeA)) * Math.cos(Math.toRadians(latitudeB)) 
                           *
                               Math.cos(Math.toRadians(longitudeB) - Math.toRadians(longitudeA))
                           +
                               Math.sin(Math.toRadians(latitudeA))
                           *
                               Math.sin(Math.toRadians(latitudeB))

                       );

    return distance;

}
Run Code Online (Sandbox Code Playgroud)

仅供参考:public static final int DISTANCE_IN_FEET = 20924640;

然后我使用Math.round(距离); 转换为长.

对于实际的25英尺,我输出7英尺.

java gps distance

2
推荐指数
1
解决办法
9655
查看次数

标签 统计

distance ×1

gps ×1

java ×1

sockjs ×1

spring ×1

spring-mvc ×1

spring-websocket ×1

stomp ×1