我正在开发一个应用程序,其中一个要求是我能够基于GPS数据执行实时反向地理编码操作.特别是,我必须能够确定纬度,经度对映射的状态/省,并检测我们何时从一个州/省迁移到另一个州/省.
到目前为止,我有几个想法,但想知道是否有人对以下任何一个有任何想法:
作为首发,以下是我的两个主要想法:
我正在python中为感兴趣的人或那些可能有他们想建议的好库的人工作.
要清楚......我没有可用的Web访问权限,因此在运行时不能使用现有的反向地理编码服务
我在这里看到另一个问题:确定iPhone用户的国家/地区可以获得iPhone用户所在的当前国家/地区.
这对于许多用途来说非常方便.但是,是否可以更深入地推断iOS(如果有信息)用户所处的州或城市?
如果事情不可能的话,我认为反向地理编码服务将是下一步.有没有可以为您的应用程序雇用的反向地理编码服务?
我尝试了两种不同的方法来尝试仅从Address类获取城市名称和州名缩写,没有运气.第一种是使用邮政编码返回状态"CA 92055",第二次尝试返回完整的州名.有什么快速的方法吗?
国家最终返回"CA 92055"的第一次尝试(Zip后面的缩写)
Geocoder geoCoder = new Geocoder(getActivity(), Locale.getDefault());
List<Address> addresses;
try {
addresses = geoCoder.getFromLocation(mLatitude, mLongitude, 10);
int i=1;
for(Address addObj:addresses)
{
// Looping once
if(i==1)
{
String add_line1_extract;
add_line1_extract=addObj.getAddressLine(1);
String string = add_line1_extract;
String[] parts = string.split(",");
//Setting city
mCity = parts[0];
//setting state
mState = parts[1];
// Final Output
String cityAndState = mCity + ", " + mState;
i++;
}
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
第二次尝试,现在越来越没有拉链......但......(返回完整的州名):
Geocoder geoCoder …Run Code Online (Sandbox Code Playgroud) 我在数据库中有超过700个地址.我想区域划分他们.我已经实现了这段代码:
public LatLng getSingleLocationFromAddress(String strAddress)
{
Geocoder coder = new Geocoder(this, Locale.getDefault());
List<Address> address = null;
Address location = null;
GeoPoint p1 = null;
LatLng temp = null;//new LatLng(26.0000, 121.0000);
String strAddresNew = strAddress.replace(",", " ");
try
{
address = coder.getFromLocationName(strAddresNew, 1);
if (!address.isEmpty())
{
location = address.get(0);
location.getLatitude();
location.getLongitude();
temp = new LatLng(location.getLatitude(), location.getLongitude());
Log.d("Latlng : ", temp + "");
} else
{
arrTemp.add(strAddress);
System.out.println(arrTemp);
}
} catch (IOException e)
{
Toast.makeText(mContext, e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (Exception e) …Run Code Online (Sandbox Code Playgroud) 我不想反转地理编码并用阿拉伯语和英语两种语言获取地址所以我想用一种语言来获取它然后改变API的语言并用另一种语言获取地址,因为我找不到参数发送到地理编码器以确定语言.有什么建议?
我试图反转地理编码一个大型数据集(大约100k).我使用revgeocode了包中的功能ggmap.我得到了一个条目的结果
48 Grand View Terrace, San Francisco,
CA 94114, USA
48 Grand View Terrace Eureka Valley San Francisco
San Francisco County California United States
postal_code postal_code_suffix
Run Code Online (Sandbox Code Playgroud)
,但我需要自动化该过程并将其用于整个数据集.
我试过了
r <- lapply(revgeocode(location = (c(z$lon),c(z$lat)),
output = "more",
messaging = FALSE, sensor = FALSE, override_limit = FALSE,
client = "", signature = ""))
Run Code Online (Sandbox Code Playgroud)
并在每一步中得到意外','的错误.
我也尝试编写以下循环
r <- for(i in 1:10){
revgeocode(location = ("z$lon", "z$lat"),output = "more", messaging = FALSE, sensor = FALSE, override_limit = FALSE,client = "", signature …Run Code Online (Sandbox Code Playgroud) 我是C#的新手并且正在使用Task.我试图运行这个应用程序但我的应用程序每次都挂起.当我添加时task.wait(),它会一直等待,永远不会返回.任何帮助深表感谢.编辑:我想异步调用DownloadString.当我按照"Austin Salonen"的建议执行task.Start()时,我没有得到位置的地址,而是从returnVal获取位置字符串中的默认值.这意味着在任务完成之前,位置得到了值.如何确保在任务完成后只有位置被指定returnVal.
public class ReverseGeoCoding
{
static string baseUri = "http://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&sensor=false";
string location = "default";
static string returnVal = "defaultRet";
string latitude = "51.962146";
string longitude = "7.602304";
public string getLocation()
{
Task task = new Task(() => RetrieveFormatedAddress(latitude, longitude));
//var result = Task.Factory.StartNew(RetrieveFormatedAddress("51.962146", "7.602304"));
task.Wait();
//RetrieveFormatedAddress("51.962146", "7.602304");
location = returnVal;
return location;
}
public static void RetrieveFormatedAddress(string lat, string lng)
{
string requestUri = string.Format(baseUri, lat, lng);
using (WebClient wc = new WebClient())
{
wc.DownloadStringCompleted …Run Code Online (Sandbox Code Playgroud) 如何使用Java中的API从地理坐标(纬度,经度)中获取地址或位置名称?Java中是否有可用的反向地理编码器?
我正在使用一个地方选择器的意图来获得这个地方.现在我想以分开的形式保存地址,如国家,城市,密码,州.我如何从地方选择器的地址获得所有这些?
码:
public class NameOfBusinessFragment extends Fragment {
int PLACE_PICKER_REQUEST = 1;
int RESULT_OK = -1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
EditText category,location;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_name_of_business,
container, false);
location = (EditText)view.findViewById(R.id.location);
location.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
startActivityForResult(builder.build(getActivity()), PLACE_PICKER_REQUEST);
}
catch (GooglePlayServicesRepairableException e)
{
Toast.makeText(getActivity(),"ServiceRepaire Exception",Toast.LENGTH_SHORT).show();
}
catch (GooglePlayServicesNotAvailableException e)
{
Toast.makeText(getActivity(),"SeerviceNotAvailable Exception",Toast.LENGTH_SHORT).show();
}
}
});
return view;
}
public void onActivityResult(int requestCode, int …Run Code Online (Sandbox Code Playgroud) 我正在使用 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