-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGooglePoint.java
More file actions
78 lines (70 loc) · 1.66 KB
/
GooglePoint.java
File metadata and controls
78 lines (70 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package homeaway;
import org.json.JSONException;
import org.json.JSONObject;
/**
* A class which represent a GooglePoint
* @author gueniot
*
*/
public class GooglePoint {
public String id;
public double latitude;
public double longitude;
public String name;
public String vicinity ;
public String types;
public double rating ;
/**
* Default constructor
*/
public GooglePoint(){
this.id = "";
this.latitude = 0;
this.longitude = 0;
this.name = "";
this.vicinity = "";
this.types = "";
this.rating = 0;
}
/**
* Constructor
* @param result The JSON return of an API request
*/
public GooglePoint(JSONObject result){
try{
JSONObject location = result.getJSONObject("geometry").getJSONObject("location");
this.id = result.get("id").toString();
this.latitude = location.getDouble("lat");
this.longitude = location.getDouble("lng");
this.name = result.get("name").toString();
this.vicinity = result.get("vicinity").toString();
this.types = result.getJSONArray("types").toString();
this.types = this.types.replace("[", "");
this.types = this.types.replace("]", "");
if(!result.isNull("rating")){
this.rating = result.getDouble("rating");
}
}
catch(JSONException e){
System.out.println(e);
}
}
/**
* Return an object in CSV
* @return
*/
public String toCSV(){
return latitude + ";" + longitude + ";" + name + ";" + vicinity + ";" + types + ";" + rating;
}
/**
* Check equality between two points
* @param point
* @return A boolean
*/
public boolean equals(GooglePoint point){
return (point.id.equals(this.id));
}
public int hashCode(){
return id.hashCode() * 31;
}
}