Him*_*wat 4 android parcelable firebase google-cloud-firestore
我使用 Cloud Firestore 作为我的数据库,在每个文档中都有一个名为 restaurant_info 的地图,它通常存储 <"name","Name of The Restaurant">, <"Location",GEOPoint of the Restaurant> 等等领域。问题是 Geo Point 类没有实现 Parcelable 或 Serializable 接口。
有两种方法可以解决这个问题。第一个是添加到Restaurant实现Parcelable接口的类中:
class Restaurant implements Parcelable {}
Run Code Online (Sandbox Code Playgroud)
然后覆盖writeToParcel()方法并创建另一个像这样的构造函数:
private GeoPoint geoPoint;
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeDouble(geoPoint.getLatitude());
parcel.writeDouble(geoPoint.getLongitude());
}
public Restaurant(Parcel in) {
Double lat = in.readDouble();
Double lng = in.readDouble();
geoPoint = new GeoPoint(lat, lng);
}
Run Code Online (Sandbox Code Playgroud)
第二种方法是存储lat并long在你的Restaurant类为双primitves,每次你需要一个GeoPoint对象,像这样创建:
GeoPoint geoPoint = new GeoPoint(restaurant.getLatitude(), restaurant.getLongitudeE6());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
661 次 |
| 最近记录: |