I'm need some help with load nearest shops. Currently I implemented to load all the shops from json which contains lat & long. But now I wanted to load all shops within 5km from current location. Some people suggest me to use distanceTo() for that, but I couldn't implement it. Please someone help with this issue?
Following code loads all the shops from the json (Works fine):
for(final Shop shop : this.response.shops){
for(int i = 0; i < shop.getShopLat().size(); i++){
map.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(shop.getShopLat().get(i)), Double.parseDouble(shop.getShopLng().get(i)))).title(shop.getName()));
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoContents(Marker marker) {
// TODO Auto-generated method stub
return null;
}
@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}
});
}
}
Edited:
LocationManager service = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = service.getBestProvider(criteria, false);
Location userLocation = service.getLastKnownLocation(provider);