0

I'm having trouble putting my current/updated location on the map which has other data. please see the image below. I need it because I will do a distance between the vehicle location and my current location, anyways how to do it? this activity is extended by fragment. I really need your help.

enter image description here

This is my OnMapReady:

public void onMapReady(GoogleMap googleMap) {
    mMapProximity = googleMap;
    mMapProximity.setBuildingsEnabled(true);
    mMapProximity.getUiSettings().setRotateGesturesEnabled(false);

    setUpMap();
}
private void setUpMap() {
    mMapProximity.clear();
    mMapProximity.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    mMapProximity.setIndoorEnabled(true);
    mMapProximity.setBuildingsEnabled(true);
    mMapProximity.getUiSettings().setZoomControlsEnabled(false);

    final Double lati = Double.parseDouble(latitudeProxListMap);
    final Double longi = Double.parseDouble(longitudeProxListMap);

    m = mMapProximity.addMarker(new MarkerOptions()
            .position(new LatLng(lati, longi))
            .anchor(0.5f, 0.5f)
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_logo))
            .visible(true));

    mMapProximity.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            marker.showInfoWindow();
        }
    });

    mMapProximity.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lati, longi), 17.0f));

    mMapProximity.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(final Marker marker) {

            if (marker.isInfoWindowShown()) {
                marker.hideInfoWindow();
            } else {
                marker.showInfoWindow();
            }

            return true;
        }
    });

    mMapProximity.setInfoWindowAdapter(new MarkerInfoWindowAdapter());

    m.showInfoWindow();
}


class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) {

        View v = getActivity().getLayoutInflater().inflate(R.layout.info_vehicle_list_map, null);
        TextView title =v.findViewById(R.id.title);
        TextView snippet =v.findViewById(R.id.snippet);
        snippet.setVisibility(View.GONE);
        title.setText("Location: " + location);
        return v;
    }

}
  • what kind of trouble you are facing ? – Vivek Mishra Nov 17 '17 at 06:09
  • hi @VivekMishra, putting my current location on the map plus the screenshot above –  Nov 17 '17 at 06:10
  • where are you adding your location on map. I can only see you are adding a marker on the map. – Vivek Mishra Nov 17 '17 at 06:13
  • my plan is to see the location of the vehicle and my current location, computing how many minutes will i travel to get on my vehicle's location and add polyline. just like on the GRAB app –  Nov 17 '17 at 06:13
  • In your current code that you have posted you haven't done anything that will show current location. – Vivek Mishra Nov 17 '17 at 06:14
  • yes as of now, my brain is turning around thinking on how to add it –  Nov 17 '17 at 06:15
  • There is not need to turn your brain around. A little google search is enough for that. https://stackoverflow.com/questions/34582370/how-can-i-show-current-location-on-a-google-map-on-android-marshmallow – Vivek Mishra Nov 17 '17 at 06:16
  • `myMap.setMyLocationEnabled(true);` add this line to show current location blue marker **Make sure it has all the required permissions** – Sara Tirmizi Nov 17 '17 at 06:17
  • im having error on this –  Nov 17 '17 at 06:19
  • ` if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) ` –  Nov 17 '17 at 06:19
  • but i had put it on my manifest –  Nov 17 '17 at 06:20
  • i tried to replace "this" to getContext, the output is the map is located at 0,0 –  Nov 17 '17 at 06:27
  • i tried the code but its not working, it wants to check permission. but i already declared permissions in my manifest –  Nov 17 '17 at 06:49

1 Answers1

1

Implement LocationListener in your activity and than in onLocationChange method update the marker with the current location values. That will put a marker on the current location.

Simo
  • 345
  • 4
  • 12