我一直在尝试验证正确的坐标格式.目前我想保存坐标.但是当格式错误时,标记将不会出现在我的地图上.
这是我的一些示例代码.
String latlon = "3.169054, 101.714108";
String regex_coords = "/\\((\\-?\\d+\\.\\d+), (\\-?\\d+\\.\\d+)\\)/";
Pattern compiledPattern2 = Pattern.compile(regex_coords, Pattern.CASE_INSENSITIVE);
Matcher matcher2 = compiledPattern2.matcher(latlon);
while (matcher2.find()) {
System.out.println("Is Valid Map Coordinate: " + matcher2.group());
}
Run Code Online (Sandbox Code Playgroud)
我希望用户能够使用逗号将此格式仅保存为"3.169054,101.714108".
任何人都可以帮助我构建正则表达式以有效这种格式吗?
谢谢大家