[英]Integrate GPS in JavafxPorts
I have a Javafx application which is to be deployed in Android. 我有一个要在Android中部署的Javafx应用程序。 My app needs to get the latitude and longitude but I dont know how to implement them.
我的应用程序需要获取经度和纬度,但我不知道如何实现。 Can someone give me a code sample on how to do it in JavaFX?
有人可以给我一个代码示例,说明如何在JavaFX中进行操作吗?
UPDATED: 更新:
package com.gpstracker;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Screen;
import javafx.stage.Stage;
public class GPSTracker extends Application {
@Override
public void start(Stage stage) {
TextField t1 = new TextField();
TextField t2 = new TextField();
Button button = new Button("Show Location");
button.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
PositionService positionService = PlatformFactory.getPlatform().getPositionService();
Position position = positionService.getPosition();
}
});
VBox root = new VBox(20);
root.setPadding(new Insets(20));
root.getChildren().addAll(t1, t2, button);
Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
Scene scene = new Scene(root, visualBounds.getWidth(), visualBounds.getHeight());
stage.setScene(scene);
stage.show();
}
}
Gloun cant seem to find a class call PositionService and Position. Gloun似乎找不到一个名为PositionService和Position的类。
With Gluon Mobile, the current position of a device can be tracked with the PositionService . 使用Gluon Mobile,可以使用PositionService跟踪设备的当前位置。 A sample code snippet:
示例代码段:
PositionService positionService = PlatformFactory.getPlatform().getPositionService();
Position position = positionService.getPosition();
System.out.println("Current GPS position: " + position.getLatitude() + "," + position.getLongitude());
This can be achieved via the Gluon Mobile library. 这可以通过Gluon Mobile库来实现。 http://gluonhq.com/products/mobile/
http://gluonhq.com/products/mobile/
To use PositionService
, mentioned by Joeri , you have to add a dependency to Gluon open source charm-down
library. 要使用Joeri提到的
PositionService
,您必须向Gluon开源超级charm-down
库添加依赖项。 Here is a sample configuration for your build.gradle
: 这是您的
build.gradle
的示例配置:
dependencies {
compile 'com.gluonhq:charm-down-common:2.0.0';
desktopRuntime 'com.gluonhq:charm-down-desktop:2.0.0';
androidRuntime 'com.gluonhq:charm-down-android:2.0.0';
iosRuntime 'com.gluonhq:charm-down-ios:2.0.0';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.