Skip to content
Snippets Groups Projects
Commit d6a1fc2a authored by chan24's avatar chan24
Browse files

userarea to map

parent a0d24ce4
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,8 @@ import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
......@@ -35,6 +37,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import static com.example.chan24.smartplanner.AppConfig.*;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener {
......@@ -42,6 +45,11 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
private GoogleMap mMap;
LocationManager locationManager;
CoordinatorLayout mainCoordinateLayout;
String shopping;
String dining;
String supermarket;
int distance;
String type;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -61,6 +69,42 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
showLocationSettings();
}
Intent i = getIntent();
shopping =i.getStringExtra("shopping");
dining=i.getStringExtra("dining");
supermarket=i.getStringExtra("supermarket");
distance= Integer.parseInt(i.getStringExtra("distance"));
StringBuilder typeBuilder=new StringBuilder();
if (shopping.contentEquals("yes")) {
typeBuilder.append("shopping_mall");
if (dining.contentEquals("yes")){
typeBuilder.append("_or_restaurant");
}
if (supermarket.contentEquals("yes")){
typeBuilder.append("_or_department_store");
}
}
else{
if (dining.contentEquals("yes")){
typeBuilder.append("restaurant");
if (supermarket.contentEquals("yes")){
typeBuilder.append("_or_department_store");
}
}
else {
if (supermarket.contentEquals("yes")){
typeBuilder.append("department_store");
}
}
}
type=typeBuilder.toString();
//Toast.makeText(getApplicationContext(),type,Toast.LENGTH_LONG).show();
}
private void showLocationSettings() {
......@@ -162,11 +206,11 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
}
private void loadNearByPlaces(double latitude, double longitude) {
String type = "restaurant";
StringBuilder googlePlacesUrl =
new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
googlePlacesUrl.append("location=").append(latitude).append(",").append(longitude);
googlePlacesUrl.append("&radius=").append(PROXIMITY_RADIUS);
googlePlacesUrl.append("&radius=").append(distance);
googlePlacesUrl.append("&types=").append(type);
googlePlacesUrl.append("&sensor=true");
googlePlacesUrl.append("&key=" + GOOGLE_BROWSER_API_KEY);
......@@ -188,6 +232,8 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
});
AppController.getInstance().addToRequestQueue(request);
}
private void parseLocationResult(JSONObject result) {
......@@ -219,16 +265,41 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
reference = place.getString(REFERENCE);
icon = place.getString(ICON);
String t=place.getString("types");
//Toast.makeText(getApplicationContext(),t,Toast.LENGTH_SHORT).show();
MarkerOptions markerOptions = new MarkerOptions();
LatLng latLng = new LatLng(latitude, longitude);
if (t.contains("restaurant") || t.contains("food")){
markerOptions.position(latLng);
markerOptions.title(placeName + " : " + vicinity);
markerOptions.icon((BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
mMap.addMarker(markerOptions);
}
else if (t.contains("department_store")){
markerOptions.position(latLng);
markerOptions.title(placeName + " : " + vicinity);
markerOptions.icon((BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
Toast.makeText(getBaseContext(), jsonArray.length() + " Supermarkets found!",
Toast.LENGTH_LONG).show();
mMap.addMarker(markerOptions);
}
else {
markerOptions.position(latLng);
markerOptions.title(placeName + " : " + vicinity);
markerOptions.icon((BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
mMap.addMarker(markerOptions);
}
/*markerOptions.position(latLng);
markerOptions.title(placeName + " : " + vicinity);
markerOptions.icon((BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
mMap.addMarker(markerOptions);*/
}
Toast.makeText(getBaseContext(), jsonArray.length() + " Supermarkets found!",Toast.LENGTH_LONG).show();
} else if (result.getString(STATUS).equalsIgnoreCase(ZERO_RESULTS)) {
Toast.makeText(getBaseContext(), "No Supermarket found in 5KM radius!!!",
Toast.LENGTH_LONG).show();
......
......@@ -12,6 +12,7 @@ import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;
......@@ -80,7 +81,6 @@ public class UserArea extends AppCompatActivity {
switch (item.getItemId()){
case R.id.my_profile :
Intent i =new Intent(getApplicationContext(),ProfileActivity.class);
i.putExtra("Name",s);
startActivity(i);
mDrawerLayout.closeDrawers();
break;
......@@ -101,6 +101,41 @@ public class UserArea extends AppCompatActivity {
return false;
}
});
Button save =(Button)findViewById(R.id.save);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBox sh =(CheckBox)findViewById(R.id.shopping);
CheckBox d =(CheckBox)findViewById(R.id.dining);
CheckBox s =(CheckBox)findViewById(R.id.supermarket);
TextView dist =(TextView)findViewById(R.id.distance);
String shopping="no";
String dining="no";
String supermarket="no";
String distance;
if(sh.isChecked()){
shopping="yes";
}
if (d.isChecked()){
dining="yes";
}
if (s.isChecked()){
supermarket="yes";
}
distance=dist.getText().toString();
Intent i = new Intent(getApplicationContext(),MapsActivity.class);
i.putExtra("shopping",shopping);
i.putExtra("dining",dining);
i.putExtra("supermarket",supermarket);
i.putExtra("distance",distance);
startActivity(i);
}
});
}
@Override
......
app/src/main/res/drawable/blue_marker.png

3.38 KiB

app/src/main/res/drawable/green_marker.png

19.8 KiB

<?xml version="1.0"?><svg width="2481" height="2073" xmlns="http://www.w3.org/2000/svg">
<title>map marker</title>
<g>
<title>Layer 1</title>
<path fill-rule="evenodd" clip-rule="evenodd" fill="#ff7f00" stroke="#000000" stroke-width="37" stroke-miterlimit="10" d="m1075.939941,1959.629028c-38.765869,-190.301025 -107.115906,-348.665039 -189.902954,-495.439941c-61.406982,-108.87207 -132.543945,-209.363037 -198.364014,-314.937988c-21.971985,-35.244019 -40.93396,-72.477051 -62.046997,-109.054077c-42.215942,-73.136963 -76.44397,-157.934998 -74.268982,-267.932007c2.125,-107.472961 33.208008,-193.68396 78.029968,-264.171997c73.719055,-115.934967 197.20105,-210.988983 362.884033,-235.968994c135.466064,-20.423981 262.475098,14.082031 352.542969,66.748016c73.600098,43.037994 130.596069,100.527008 173.920044,168.279999c45.219971,70.716003 76.359009,154.26001 78.970947,263.231995c1.337036,55.830017 -7.804932,107.531982 -20.68396,150.417969c-13.033936,43.409058 -33.995972,79.695007 -52.645996,118.454102c-36.406006,75.658936 -82.04895,144.981934 -127.85498,214.345947c-136.437012,206.605957 -264.496094,417.309937 -320.580078,706.026978z" id="svg_2"/>
<circle fill-rule="evenodd" clip-rule="evenodd" cx="1080.546" cy="740.047" r="183.332031" id="svg_4" fill="black"/>
</g>
</svg>
\ No newline at end of file
app/src/main/res/drawable/red_marker.jpg

2.75 KiB

......@@ -38,13 +38,13 @@
android:text="Shopping" />
<CheckBox
android:id="@+id/Movies"
android:id="@+id/supermarket"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Movies" />
android:text="Supermarket" />
<CheckBox
android:id="@+id/Dining"
android:id="@+id/dining"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Dining" />
......@@ -57,14 +57,15 @@
android:textColor="@color/colorPrimary"
android:layout_marginTop="30dp"
/>
<EditText
android:id="@+id/distance"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="20dp"
android:inputType="number"
android:hint="Distance in km"
/>
android:inputType="number" />
<Button
android:id="@+id/save"
android:layout_width="wrap_content"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment