Skip to content

Commit 934c8d2

Browse files
authored
Merge pull request #23 from pulkit4tech/JSON_parsing
#21 : Parsing JSON data using GSON
2 parents 41fd208 + 2d37f3c commit 934c8d2

File tree

9 files changed

+275
-74
lines changed

9 files changed

+275
-74
lines changed

app/src/main/java/com/pulkit4tech/privy/PrivyMapsActivity.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
import com.google.android.gms.maps.SupportMapFragment;
1818
import com.google.android.gms.maps.model.CameraPosition;
1919
import com.google.android.gms.maps.model.LatLng;
20-
import com.google.android.gms.maps.model.Marker;
21-
import com.google.android.gms.maps.model.MarkerOptions;
2220
import com.pulkit4tech.privy.data.LocationData;
21+
import com.pulkit4tech.privy.data.json.MarkerData;
2322
import com.pulkit4tech.privy.utilities.LocationServices;
2423
import com.pulkit4tech.privy.utilities.RequestData;
2524

25+
import java.util.HashMap;
26+
2627
import static com.pulkit4tech.privy.constants.Constants.DEBUG;
2728
import static com.pulkit4tech.privy.constants.Constants.CAMERA_ANIMATION_DURATION;
2829
import static com.pulkit4tech.privy.constants.Constants.MY_PERMISSIONS_REQUEST_FINE_LOCATIONS;
@@ -31,10 +32,10 @@ public class PrivyMapsActivity extends ActionBarActivity implements OnMapReadyCa
3132

3233
private GoogleMap mMap;
3334
private Context mContext;
34-
private Marker myLocationMarker;
3535
private CameraPosition MY_LOCATION_CAMERA_POS;
36+
private HashMap<Integer,MarkerData> universalMarkers;
3637

37-
// My Location
38+
// My location
3839
private LocationData myLocationData;
3940

4041
@Override
@@ -113,20 +114,13 @@ private void getMyCurrentLocation(){
113114
myLocationData = locationService.getCurrentLocation();
114115
if(myLocationData!=null) {
115116

116-
// checking for previous marker and if present, replacing it with new marker
117-
if (myLocationMarker != null) {
118-
myLocationMarker.remove();
119-
}
120-
121117
MY_LOCATION_CAMERA_POS = new CameraPosition.Builder()
122118
.target(myLocationData.getLatLng())
123119
.zoom(15.0f)
124120
.bearing(0)
125121
.tilt(25)
126122
.build();
127123

128-
myLocationMarker = mMap.addMarker(new MarkerOptions().position(myLocationData.getLatLng()).title("My Location"));
129-
130124
//animate camera
131125
moveCameraToMyLocation();
132126
addMarkers();
@@ -178,6 +172,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
178172
}
179173

180174
private void markNearbyPrivys(LatLng myLocation){
181-
new RequestData(mContext,mMap,myLocation).getMarkerData();
175+
universalMarkers = new HashMap<>();
176+
new RequestData(mContext,mMap,universalMarkers,myLocation).getMarkerData();
182177
}
183178
}

app/src/main/java/com/pulkit4tech/privy/data/MarkerData.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/src/main/java/com/pulkit4tech/privy/data/PrivyPost.java

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.pulkit4tech.privy.data.json;
2+
3+
public class Location {
4+
private double lat;
5+
private double lng;
6+
7+
public double getLat() {
8+
return lat;
9+
}
10+
11+
public void setLat(double lat) {
12+
this.lat = lat;
13+
}
14+
15+
public double getLng() {
16+
return lng;
17+
}
18+
19+
public void setLng(double lng) {
20+
this.lng = lng;
21+
}
22+
23+
@Override
24+
public String toString() {
25+
return "Location{" +
26+
"lat=" + lat +
27+
", lng=" + lng +
28+
'}';
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.pulkit4tech.privy.data.json;
2+
3+
public class LocationData {
4+
private Location location;
5+
6+
public void setLocation(Location location) {
7+
this.location = location;
8+
}
9+
10+
public Location getLocation() {
11+
return location;
12+
}
13+
14+
@Override
15+
public String toString() {
16+
return "LocationData{" +
17+
"location=" + location +
18+
'}';
19+
}
20+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.pulkit4tech.privy.data.json;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
import java.util.List;
6+
7+
public class MarkerData {
8+
private LocationData geometry;
9+
10+
@SerializedName("icon")
11+
private String icon_url;
12+
private String id;
13+
private String name;
14+
private String place_id;
15+
private String scope;
16+
private List<String> types;
17+
private String vicinity;
18+
19+
public LocationData getGeometry() {
20+
return geometry;
21+
}
22+
23+
public void setGeometry(LocationData geometry) {
24+
this.geometry = geometry;
25+
}
26+
27+
public String getIconurl() {
28+
return icon_url;
29+
}
30+
31+
public void setIconurl(String icon_url) {
32+
this.icon_url = icon_url;
33+
}
34+
35+
public String getId() {
36+
return id;
37+
}
38+
39+
public void setId(String id) {
40+
this.id = id;
41+
}
42+
43+
public String getName() {
44+
return name;
45+
}
46+
47+
public void setName(String name) {
48+
this.name = name;
49+
}
50+
51+
public String getPlaceid() {
52+
return place_id;
53+
}
54+
55+
public void setPlaceid(String place_id) {
56+
this.place_id = place_id;
57+
}
58+
59+
public String getScope() {
60+
return scope;
61+
}
62+
63+
public void setScope(String scope) {
64+
this.scope = scope;
65+
}
66+
67+
public List<String> getTypes() {
68+
return types;
69+
}
70+
71+
public void setTypes(List<String> types) {
72+
this.types = types;
73+
}
74+
75+
public String getVicinity() {
76+
return vicinity;
77+
}
78+
79+
public void setVicinity(String vicinity) {
80+
this.vicinity = vicinity;
81+
}
82+
83+
@Override
84+
public String toString() {
85+
return "MarkerData{" +
86+
"geometry=" + geometry +
87+
", icon_url='" + icon_url + '\'' +
88+
", id='" + id + '\'' +
89+
", name='" + name + '\'' +
90+
", place_id='" + place_id + '\'' +
91+
", scope='" + scope + '\'' +
92+
", types=" + types +
93+
", vicinity='" + vicinity + '\'' +
94+
'}';
95+
}
96+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.pulkit4tech.privy.data.json;
2+
3+
import java.util.List;
4+
5+
public class PrivyPost {
6+
private List<String> html_attributions;
7+
private List<MarkerData> results;
8+
private String status;
9+
10+
public List<String> getHtmlattributions() {
11+
return html_attributions;
12+
}
13+
14+
public void setHtmlattributions(List<String> html_attributions) {
15+
this.html_attributions = html_attributions;
16+
}
17+
18+
public List<MarkerData> getResults() {
19+
return results;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "PrivyPost{" +
25+
"html_attributions=" + html_attributions +
26+
", results=" + results +
27+
", status='" + status + '\'' +
28+
'}';
29+
}
30+
31+
public void setResults(List<MarkerData> results) {
32+
this.results = results;
33+
}
34+
35+
public String getStatus() {
36+
return status;
37+
}
38+
39+
public void setStatus(String status) {
40+
this.status = status;
41+
}
42+
}

0 commit comments

Comments
 (0)