我正在使用 DispatchGroup.enter() 和 leave() 来处理辅助类的 reverseG 异步函数。问题很明显,我正在使用 mainViewController 的对象在 helper 类中调用 mainViewControllers 的 dispatchGroup.leave() !有没有办法做到这一点?
当在主视图控制器中声明 reverseG 时,相同的代码有效。
class Geo {
var obj = ViewController()
static func reverseG(_ coordinates: CLLocation, _ completion: @escaping (CLPlacemark) -> ()) {
let geoCoder = CLGeocoder()
geoCoder.reverseGeocodeLocation(coordinates) { (placemarks, error) in
if let error = error {
print("error: \(error.localizedDescription)")
}
if let placemarks = placemarks, placemarks.count > 0 {
let placemark = placemarks.first!
completion(placemark) // set ViewController's properties
} else {
print("no data")
}
obj.dispatchGroup.leave() …Run Code Online (Sandbox Code Playgroud) reverse-geocoding grand-central-dispatch completionhandler swift
如果将纬度或经度转换为double的公式为
((Degree) + (Minute) / 60 + (Second) / 3600) * ((South || West) ? -1 : 1)
那么从双精度解析度,分,秒的公式是什么?
有两个单独的方法来解析纬度和经度是有道理的,但我不知道如何解析双精度的度数,分钟,秒.
ParseLatitude(double value)
{
//value is South if negative, else is North.
}
ParseLongitude(double value)
{
//value is West if negative, else is East.
}
Run Code Online (Sandbox Code Playgroud)
示例坐标:
纬度:43.81234123
经度:-119.8374747
最后的代码来回转换,再次感谢Peter和James的回答.我不得不将值转换为Decimal,因为这是在Silverlight中使用而Math.Truncate(double)不可用):
public class Coordinate
{
public double Degrees { get; set; }
public double Minutes { get; set; }
public double Seconds { get; set; }
public CoordinatesPosition Position { get; …Run Code Online (Sandbox Code Playgroud) 在给定城市名称或纬度/长度组合的情况下,是否有用于查找附近城市的Bing API?
我正在Geocoder以相反的方式使用来自给定lat&lon的地址.
你知道如何从Address 街道名称获得?
Geocoder geocoder = new Geocoder(AutoFinderMapActivity.this);
try {
List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 1);
if (addressList != null && addressList.size() > 0) {
// Help here to get only the street name
String adress = addressList.get(0).get...;
}
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
提前致谢,
使用下面的代码,我正在为当前坐标请求反向地理编码.
一切都很好,除了设备设置为与英语不同的语言.
示例:如果设备的语言是意大利语,而我在意大利,则国家的结果是"Italia"而不是"Italy".
无论设备的语言如何,我如何强制结果只能用英语?
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:myCurrentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark * placemark in placemarks) {
[locationController setLastKnownCountry:[placemark country]];
}
}];
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在开发使用谷歌地图的移动应用程序,我想通过设备纬度和经度查找用户当前地址(反向地理编码)。
谷歌有一些限制,一旦超出它就会向我收费。现在我正在寻找OpenStreetMap,它是开放供公众使用的。我可以使用反向地理编码。
例如http://nominatim.openstreetmap.org/reverse?format=xml&lat=20&lon=71&zoom=18
我的问题是,1)。每天拨打这些电话有限制吗?2)。我需要在某个地方注册吗?3)。还有其他替代方案吗?
提前致谢
我有一组由两点定义的段.鉴于一点,我怎样才能发现最接近这一点的细分?
我已经编写了一个计算点和段之间距离的算法.无论如何计算每个段的这种距离,然后选择具有最低距离的段是不是真的有效:(
由于段代表街道,这实际上是一个反向地理编码问题所以我希望有这个问题的众所周知的解决方案......
非常感谢!
我见过各种语言的许多所谓的"反向地理编码"库; 所有这些都依赖于通过REST或类似方法调用外部提供程序.但是,如果每秒必须处理数千个请求,则无法调用REST提供程序.
另一方面,问题应该很容易解决 - 基于CSV的数据库可以免费获得这些信息.问题是编写高效且经过良好测试的内存中搜索实现的时间和成本,而不是下载或购买现有的搜索实现.
经过很多寻找后我找不到任何东西,但我无法相信不可能有一个.是否有预先编写的库可以执行此操作?
这个问题:
是最接近的,但基本上表明如何编写解决方案,而不是现成的任何东西.但每个人都必须使用一些库.每天十几个人一定有这个问题.
我知道网站上有很多关于以下内容的问题IOExeption:服务不可用.....我已经检查了我能找到的关于这个主题的所有答案...我正在运行它async task似乎工作得很好但仍然得到相同的例外.
我已经使用isPresent()过以前的尝试,虽然它不在以下代码中,我使用相同的手机.我有互联网许可.我试图改变目标,google api看看是不是问题,但没有区别.
这是第四年项目的重要组成部分,因此任何帮助都是严肃的.在最近之前,ps从未使用过java或android,所以请原谅任何看起来编码的菜鸟.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view1 = (TextView) findViewById(R.id.textView1);
view2 = (TextView)findViewById(R.id.textView2);
view3 = (TextView)findViewById(R.id.textView4);
b1 = (Button) findViewById(R.id.button1);
locationManager =
(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
//provider =
// locationManager.getProvider(LocationManager.GPS_PROVIDER);
final LocationListener listener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
view2.setText(Double.toString(location.getLatitude()));
view3.setText(Double.toString(location.getLongitude()));
Double lat = Double.valueOf(location.getLatitude());
Double longTemp = Double.valueOf(location.getLatitude());
new geo().execute(lat,longTemp);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub …Run Code Online (Sandbox Code Playgroud) 我必须在 R 中对几个地址进行地理编码,但收到“已达到超时:连接在 10000 毫秒后超时”错误。我在办公室防火墙后面,所以也尝试使用代理,但仍然遇到相同的错误。
当我使用源作为“dsk”但它不会对大多数地址进行地理编码时,这有效,因此想要使用“google”作为源。
下面是我使用的一段代码。
library(ggmap)
library(curl)
register_google(key = "Have_Entered_My_API_Key_Here")
#Used below code to use proxy...(saw it as a solution in stackoverflow only for working behind firewall..maybe I'm not doing it the correct way?)
library(httr)
set_config(use_proxy(url="10.3.100.207",port=8080))
origAddress <- read.csv("Data_for_Geocoding.csv",header = TRUE,sep = ",",stringsAsFactors = FALSE)
for(i in 1:nrow(origAddress))
{
result <- geocode(origAddress$Add_to_GeoCode[i], output = "latlona", source = "google",sensor = TRUE)
origAddress$LONGITUDE[i] <- as.numeric(result[1])
origAddress$LATITUDE[i] <- as.numeric(result[2])
# origAddress$ <- as.character(result[3])
}
Run Code Online (Sandbox Code Playgroud)
运行此代码时出现以下错误。
“在 curl::curl_fetch_memory(url, handle = handle) 中出错:达到超时:连接在 …
geocoding r reverse-geocoding google-geocoder google-geocoding-api