首页
\
问答
\
在Android中,如何获取当前位置并获取3km或5km距离内的注册用户位置?(In Android,How to get current Location and getting the registered user location within 3km or 5km distance?)
在Android中,如何获取当前位置并获取3km或5km距离内的注册用户位置?(In Android,How to get current Location and getting the registered user location within 3km or 5km distance?)
我是android的新手,任何人都可以帮我解决我的问题....如何获取当前位置并获得3km或5km距离内的注册用户位置??????
它就像一个查找出租车,显示出租车附近的用户位置。 我可以使用此代码获取当前位置。
// Getting LocationManager object from System Service LOCATION_SERVICE LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // Creating a criteria object to retrieve provider Criteria criteria = new Criteria(); // Getting the name of the best provider String provider = locationManager.getBestProvider(criteria, true); // Getting Current Location From GPS Location location = locationManager.getLastKnownLocation(provider); if(location!=null){ onLocationChanged(location); } locationManager.requestLocationUpdates(provider, 20000, 0, this); final LatLng latLng = new LatLng(mLatitude, mLongitude); Toast.makeText(MainActivity.this, " "+latLng, Toast.LENGTH_SHORT).show(); @Override public void onLocationChanged(Location location) { mLatitude = location.getLatitude(); mLongitude = location.getLongitude(); } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { }
I am new to android, can anyone help me for my question.... How to get current Location and getting the registered user's location available within 3km or 5km distance??????
It's like a Find Taxi to show the user location nearby the taxi available. I can get current location by using this code.
// Getting LocationManager object from System Service LOCATION_SERVICE LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // Creating a criteria object to retrieve provider Criteria criteria = new Criteria(); // Getting the name of the best provider String provider = locationManager.getBestProvider(criteria, true); // Getting Current Location From GPS Location location = locationManager.getLastKnownLocation(provider); if(location!=null){ onLocationChanged(location); } locationManager.requestLocationUpdates(provider, 20000, 0, this); final LatLng latLng = new LatLng(mLatitude, mLongitude); Toast.makeText(MainActivity.this, " "+latLng, Toast.LENGTH_SHORT).show(); @Override public void onLocationChanged(Location location) { mLatitude = location.getLatitude(); mLongitude = location.getLongitude(); } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { }
原文:https://stackoverflow.com/questions/32990055
更新时间:2021-11-17 17:11
最满意答案
你可以在
let
添加cast。if let tmp = objData.object(forKey: "Message") as? String { msg = tmp }
You can add casting in
let
.if let tmp = objData.object(forKey: "Message") as? String { msg = tmp }
相关问答
更多-
如果你用宏包装它可能会更容易一些: #define NULL_TO_NIL(obj) ({ __typeof__ (obj) __obj = (obj); __obj == [NSNull null] ? nil : obj; }) 然后你可以写出类似的东西 fight.winnerID = NULL_TO_NIL([dict objectForKey:@"winner"]); 或者,你可以预先处理你的字典,并用nil替换所有的NSNull s,甚至试图将其填充到管理对象中。 It might be a ...
-
nil,NULL和[NSNULL nil]之间有什么区别?(What are the differences between nil, NULL and [NSNULL nil]?)[2022-11-29]
NULL是给予指向它的原始C风格值,该指针被认为指向没有显式地址。 它通常只是用来表示“未设置”或作为定点值 。 char * oldstring = NULL; nil是应用于Obj-C对象引用的Objective-C版本: NSString * str = nil; id foo = nil; 它们都被定义为等于零值,虽然你可以交替使用它们,但前者主要在Obj-C中看到,用于传统指针(如将void *上下文指针设置为NULL), nil用于所有Obj- C对象引用。 不同之处在于,尽管Obj-C的语 ... -
您可以通过检查来检查虚假值 if (!value) { //do work here } 对于0 , "" , null , undefined , false和NaN ,将评估为true 或者当然如果你想测试该字段是否为空,你可以检查一个truthy值 if (value) { //do work here } 如果值不是 falsy则评估为true (以上都不是) You could do a check for a falsy values by just checking for ...
-
如果您使用的是JSONDecoder ,则缺省值和显式指定为null将返回nil : 考虑这个JSON: {"foo": "a", "bar": null} 这个struct : struct Result: Decodable { var foo: String var bar: String? var baz: String? } 如果您使用JSONDecoder ,您可以这样做: guard let result = try? JSONDecoder().decode(Re ...
-
这不是多余的一步吗? 因为,编译器确保该字段是静态的。 如果有人手动创建字节码(或使用字节码修改库),那么这些编译器检查就不会发生。 这就是我们需要在加载时验证字节码的原因。 Isn't it redundant step? Because, compiler ensures the field is static. If someone creates the bytecodes by hand (or using a bytecode modification library), then those ...
-
可能是一些问题: 仔细检查你的班级名称是“riderRequest”,我认为“RiderRequest”可能是实际的名字。 其次是通过转到解析仪表板并查看您的课程来检查所有的关键名称是否正确 最后一件事是确认在设置之前,用户名,纬度和经度等所有值都不是零。 也许试试: if let username = PFUser.currentUser()?.username && latitude != nil && longitude != nil { riderRequest.setObject(use ...
-
你可以在let添加cast。 if let tmp = objData.object(forKey: "Message") as? String { msg = tmp } You can add casting in let. if let tmp = objData.object(forKey: "Message") as? String { msg = tmp }
-
只需更换你的 var prevNotifCount = self.cmmn.getPreviousNotificationCount() as? String 并使用 guard let prevNotifCount = self.cmmn.getPreviousNotificationCount() else{ print("No previous notification value") return } 不需 ...
-
您需要使用typeof函数返回未评估操作数的类型。 var body = JSON.parse(responseBody); tests["sign_in_count is number"] = typeof(body.data.sign_in_count) === "number"; tests["firstname is string"] = typeof(body.data.firstname) === "string"; You need to use typeof function which r ...
-
Type genericSuperclass = x.getClass().getGenericSuperclass(); if (genericSuperclass instanceof ParameterizedType) { Type[] types = ((ParameterizedType) genericSuperclass).getActualTypeArguments(); } 然后,如果type instanceof Class ,则可以使用Class.isAss ...