我是一个Android初学者,无法在任何地方找到答案。
我想在地图上显示距离地图中心25公里的标记。 我找不到找到地图中心位置的方法,然后显示距离它25公里的标记。
地理位置在Cars.class中的Parse.com上,位于“位置”行。 到目前为止,事件代码显示标记不起作用,它得到的结果:
{"objectId": "[...]","location": {"__type":"GeoPoint","latitude": [...],"longitude": [...] },"createdAt":"[...]","updatedAt": "[...]"}它崩溃并给我错误:
com.parse.ParseObject无法强制转换为com.company.test.Cars。
谢谢您的帮助!
ParseQuery<Cars> query = ParseQuery.getQuery("Cars"); query.selectKeys(Collections.singletonList("location")); query.findInBackground(new FindCallback<Cars>(){ @Override public void done(List<Cars> list, ParseException e) { if (e != null) { return; } ParseGeoPoint geoPoint; for(int i =0;i<list.size();i++){ geoPoint = list.get(i).getParseGeoPoint("location"); mMap.addMarker(new MarkerOptions().position(new LatLng(geoPoint.getLatitude(), geoPoint.getLongitude())));I am an android beginner and can't find the answer anywhere.
I want to show the markers on the map that are 25 km from the center of the map. I can't find the way to find the location of the center of the map, then show the markers that are 25km from it.
The geopoints are on Parse.com in the Cars.class, in the row "location". So far, event the code to show the markers doesn't work, it gets the results:
{"objectId": "[...]","location": {"__type":"GeoPoint","latitude": [...],"longitude": [...] },"createdAt":"[...]","updatedAt": "[...]"}It crashes and gives me the error:
com.parse.ParseObject cannot be cast to com.company.test.Cars.
Thanks for the help!
ParseQuery<Cars> query = ParseQuery.getQuery("Cars"); query.selectKeys(Collections.singletonList("location")); query.findInBackground(new FindCallback<Cars>(){ @Override public void done(List<Cars> list, ParseException e) { if (e != null) { return; } ParseGeoPoint geoPoint; for(int i =0;i<list.size();i++){ geoPoint = list.get(i).getParseGeoPoint("location"); mMap.addMarker(new MarkerOptions().position(new LatLng(geoPoint.getLatitude(), geoPoint.getLongitude())));最满意答案
好的,有两个选项可以实现您的尝试。
一个有点复杂但非常强大: 这里描述了一切
顺便说一句,你应用这个选项后,它将是:
ParseQuery<Cars> query = ParseQuery.getQuery(Cars.class);另一个对我来说听起来不那么复杂:
创建一个Parse.Query<Parse.Object>来获取Parse.Object而不是Cars 。 在done方法中,遍历所有结果 创建一个Car的构造函数,它将Parse.Object作为参数 通过刚创建的构造函数将每个Parse.Object从结果转换为Car对象。第二种选择可能有点复杂,但更灵活。
Ok so there is two options to achieve what you try to do.
One is a bit complicated but very powerful: everything is described here
Btw after you apply this option, it will be:
ParseQuery<Cars> query = ParseQuery.getQuery(Cars.class);The other would sound less complex to me:
Create a Parse.Query<Parse.Object> to get Parse.Object instead of Cars. In the done method, iterate through all the result Create a constructor of Car which takes a Parse.Object as parameter Convert every Parse.Object from the results into a Car Object via the constructor you just created.This second option is maybe a bit more complex but way more flexible.
更多推荐
location,com,Cars,geoPoint,markers,电脑培训,计算机培训,IT培训"/> <meta name=
发布评论