How to make GEO Point Class Parcelable or Serializable as I want to pass them using Intent
I am using Cloud Firestore as my Database and in every document there is a Map named restaurant_info that has as it typically stores <"name","Name of The Restaurant">, <"Location",GEOPoint of the Restaurant> and some more fields. The problem is the Geo Point class doesn't implement Parcelable or Serializable interface.
add a comment |
I am using Cloud Firestore as my Database and in every document there is a Map named restaurant_info that has as it typically stores <"name","Name of The Restaurant">, <"Location",GEOPoint of the Restaurant> and some more fields. The problem is the Geo Point class doesn't implement Parcelable or Serializable interface.
add a comment |
I am using Cloud Firestore as my Database and in every document there is a Map named restaurant_info that has as it typically stores <"name","Name of The Restaurant">, <"Location",GEOPoint of the Restaurant> and some more fields. The problem is the Geo Point class doesn't implement Parcelable or Serializable interface.
I am using Cloud Firestore as my Database and in every document there is a Map named restaurant_info that has as it typically stores <"name","Name of The Restaurant">, <"Location",GEOPoint of the Restaurant> and some more fields. The problem is the Geo Point class doesn't implement Parcelable or Serializable interface.
edited Nov 26 '18 at 14:56
Frank van Puffelen
235k29381407
235k29381407
asked Nov 26 '18 at 13:20
Himanshu RawatHimanshu Rawat
15118
15118
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
There are two ways in which you can solve this. The first one would be to add to your Restaurant class that implements the Parcelable interface:
class Restaurant implements Parcelable {}
And then override writeToParcel() method and create another constructor like this:
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);
}
The second approach would be to store the lat and long in your Restaurant class as double primitves and everytime you need a GeoPoint object, create it like this:
GeoPoint geoPoint = new GeoPoint(restaurant.getLatitude(), restaurant.getLongitudeE6());
Hi Himanshu! Have you tried my solution above, does it work?
– Alex Mamo
Nov 27 '18 at 9:15
Thanks Alex it helped me a lot.
– Himanshu Rawat
Nov 27 '18 at 10:57
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482035%2fhow-to-make-geo-point-class-parcelable-or-serializable-as-i-want-to-pass-them-us%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are two ways in which you can solve this. The first one would be to add to your Restaurant class that implements the Parcelable interface:
class Restaurant implements Parcelable {}
And then override writeToParcel() method and create another constructor like this:
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);
}
The second approach would be to store the lat and long in your Restaurant class as double primitves and everytime you need a GeoPoint object, create it like this:
GeoPoint geoPoint = new GeoPoint(restaurant.getLatitude(), restaurant.getLongitudeE6());
Hi Himanshu! Have you tried my solution above, does it work?
– Alex Mamo
Nov 27 '18 at 9:15
Thanks Alex it helped me a lot.
– Himanshu Rawat
Nov 27 '18 at 10:57
add a comment |
There are two ways in which you can solve this. The first one would be to add to your Restaurant class that implements the Parcelable interface:
class Restaurant implements Parcelable {}
And then override writeToParcel() method and create another constructor like this:
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);
}
The second approach would be to store the lat and long in your Restaurant class as double primitves and everytime you need a GeoPoint object, create it like this:
GeoPoint geoPoint = new GeoPoint(restaurant.getLatitude(), restaurant.getLongitudeE6());
Hi Himanshu! Have you tried my solution above, does it work?
– Alex Mamo
Nov 27 '18 at 9:15
Thanks Alex it helped me a lot.
– Himanshu Rawat
Nov 27 '18 at 10:57
add a comment |
There are two ways in which you can solve this. The first one would be to add to your Restaurant class that implements the Parcelable interface:
class Restaurant implements Parcelable {}
And then override writeToParcel() method and create another constructor like this:
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);
}
The second approach would be to store the lat and long in your Restaurant class as double primitves and everytime you need a GeoPoint object, create it like this:
GeoPoint geoPoint = new GeoPoint(restaurant.getLatitude(), restaurant.getLongitudeE6());
There are two ways in which you can solve this. The first one would be to add to your Restaurant class that implements the Parcelable interface:
class Restaurant implements Parcelable {}
And then override writeToParcel() method and create another constructor like this:
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);
}
The second approach would be to store the lat and long in your Restaurant class as double primitves and everytime you need a GeoPoint object, create it like this:
GeoPoint geoPoint = new GeoPoint(restaurant.getLatitude(), restaurant.getLongitudeE6());
answered Nov 26 '18 at 13:37
Alex MamoAlex Mamo
43k82860
43k82860
Hi Himanshu! Have you tried my solution above, does it work?
– Alex Mamo
Nov 27 '18 at 9:15
Thanks Alex it helped me a lot.
– Himanshu Rawat
Nov 27 '18 at 10:57
add a comment |
Hi Himanshu! Have you tried my solution above, does it work?
– Alex Mamo
Nov 27 '18 at 9:15
Thanks Alex it helped me a lot.
– Himanshu Rawat
Nov 27 '18 at 10:57
Hi Himanshu! Have you tried my solution above, does it work?
– Alex Mamo
Nov 27 '18 at 9:15
Hi Himanshu! Have you tried my solution above, does it work?
– Alex Mamo
Nov 27 '18 at 9:15
Thanks Alex it helped me a lot.
– Himanshu Rawat
Nov 27 '18 at 10:57
Thanks Alex it helped me a lot.
– Himanshu Rawat
Nov 27 '18 at 10:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482035%2fhow-to-make-geo-point-class-parcelable-or-serializable-as-i-want-to-pass-them-us%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown