将字符串转换为LatLng [英] Convert String to LatLng
本文介绍了将字符串转换为LatLng的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Google Maps API v2,并且从我需要转换为LatLng的SharedPreferences中获得了位置坐标单个字符串"-34.8799074,174.7565664".
I'm using Google Maps API v2 and I get a location coordinates single String "-34.8799074,174.7565664" from my SharedPreferences that I need to convert to LatLng.
任何人都可以帮忙吗?
谢谢!
推荐答案
[Google Maps Android API]
您可以用逗号分割字符串,然后将其解析为长
You can split the string by comma and then parse the string to long
String[] latlong = "-34.8799074,174.7565664".split(",");
double latitude = Double.parseDouble(latlong[0]);
double longitude = Double.parseDouble(latlong[1]);
要构建 LatLng 具有给定的纬度和经度坐标
To constructs a LatLng with the given latitude and longitude coordinates
LatLng location = new LatLng(latitude, longitude);
[Google Maps JavaScript API]
要使用Maps JavaScript API服务执行相同的操作( JSFiddle演示)-
To do same operation with Maps JavaScript API service (JSFiddle demo) -
var latlong = '-34.397,150.644'.split(',');
var latitude = parseFloat(latlong[0]);
var longitude = parseFloat(latlong[1]);
var mapOptions = {
zoom: 8,
center: {lat: latitude, lng: longitude}
};
这篇关于将字符串转换为LatLng的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文