0

I have different files for my geolocation and for the markers :D what i want to do is to draw a line... my position (using gps) to the marker I already inputed in application. that if i clicked one marker i choose there will be line :) THANK YOU I'm new to this please help me..

//this is my locationHelper

public static GoogleMap getStoreList(GoogleMap googleMap){

        // create marker
        MarkerOptions seveneleven = new MarkerOptions().position(new LatLng(14.616737, 120.982916)).title("7-Eleven");
        googleMap.addMarker(seveneleven);

        MarkerOptions sevenelevenRecto = new MarkerOptions().position(new LatLng(14.601643, 120.988580)).title("7-Eleven Recto");
        googleMap.addMarker(sevenelevenRecto);

        MarkerOptions newestGroceryEnColdStore = new MarkerOptions().position(new LatLng(14.597770, 120.983253)).title("Newest Grocery and Cold Store");
        googleMap.addMarker(newestGroceryEnColdStore);

        MarkerOptions savemoreStaCruz = new MarkerOptions().position(new LatLng(14.601845, 120.981116)).title("Savemore Sta Cruz");
        googleMap.addMarker(savemoreStaCruz);

        MarkerOptions sevenTondo = new MarkerOptions().position(new LatLng(14.63059, 120.97355 )).title("7-Eleven (Pampanga St, Tondo, Manila)");
        googleMap.addMarker(sevenTondo);

        MarkerOptions sevenTayuman = new MarkerOptions().position(new LatLng(14.65086, 120.98248 )).title("7-Eleven (Tayuman Road, Sta. Cruz, Manila)");
        googleMap.addMarker(sevenTayuman);

        MarkerOptions miniStopm = new MarkerOptions().position(new LatLng(14.64239, 120.98694 )).title("Ministop (Sampaloc, Manila))");
        googleMap.addMarker(miniStopm);

        MarkerOptions miniStopmm = new MarkerOptions().position(new LatLng(14.63657, 120.98505 )).title("Vosges Convenience Store (G/F Old Free Press Bldg Soler St, Quiapo, Manila))");
        googleMap.addMarker(miniStopmm);

        MarkerOptions miniStopmp = new MarkerOptions().position(new LatLng(14.60555, 120.98853 )).title("Mini Stop (Padre Campa St. Sampaloc, Manila)");
        googleMap.addMarker(miniStopmp);

        MarkerOptions savemoreStacruz = new MarkerOptions().position(new LatLng(14.57734, 120.99197 )).title("Savemore (Sta. Cruz, Manila)");
        googleMap.addMarker(savemoreStacruz);

        MarkerOptions super8recto = new MarkerOptions().position(new LatLng(14.601971, 120.987858)).title("Super 8 Recto");
        googleMap.addMarker(super8recto);

        return googleMap;
    }


//this is my another file which is my geolocation in my mainActivity.
GAMITG
  • 3,810
  • 7
  • 32
  • 51

2 Answers2

0

If you already have Lat-Long of source and destination than you can use below code.

 private List<LatLng> decodePoly(String encoded) {

List<LatLng> poly = new ArrayList<LatLng>();
int index = 0, len = encoded.length();
int lat = 0, lng = 0;

while (index < len) {
    int b, shift = 0, result = 0;
    do {
        b = encoded.charAt(index++) - 63;
        result |= (b & 0x1f) << shift;
        shift += 5;
    } while (b >= 0x20);
    int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
    lat += dlat;

    shift = 0;
    result = 0;
    do {
        b = encoded.charAt(index++) - 63;
        result |= (b & 0x1f) << shift;
        shift += 5;
    } while (b >= 0x20);
    int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
    lng += dlng;

    LatLng p = new LatLng( (((double) lat / 1E5)),
             (((double) lng / 1E5) ));
    poly.add(p);
}

  return poly;
}

Please refer to this link for detail information.

Community
  • 1
  • 1
Jay Savsani
  • 299
  • 1
  • 3
  • 16
  • I have different files for my geolocation and for the markers i inputted.. where do i need to put this codes? – Jomabell Lascano Oct 10 '15 at 07:39
  • If possible please post your both files full code here. – Jay Savsani Oct 10 '15 at 07:43
  • String category = getIntent().getStringExtra("category"); /** * Set the marker for the appropriate category */ if(category.equalsIgnoreCase("CONVENIENCE STORES")){ googleMap = LocationHelper.getStoreList(googleMap); }else if(category.equalsIgnoreCase("HOSPITALS")){ googleMap = LocationHelper.getHospilalList(googleMap); }else if(category.equalsIgnoreCase("EVACUATION CENTERS")){ googleMap = LocationHelper.getEvacCenterList(googleMap); } – Jomabell Lascano Oct 10 '15 at 08:04
  • i put other codes for answer I can't comments all the codes its a big file :3 if you want to see my codes i will give to you :3 for you to see it. i just need i help – Jomabell Lascano Oct 10 '15 at 08:05
  • where should I put the codes to the LocationHelper which contains the markers on the map or to my MainActivity containing my gps location? – Jomabell Lascano Oct 10 '15 at 08:27
0
            googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {

                @Override
                public void onMyLocationChange(Location arg0) {
                    googleMap.addMarker(new MarkerOptions().position(new LatLng(arg0.getLatitude(), arg0.getLongitude())).title("Your Location!"));

                    CameraPosition cameraPosition = new CameraPosition.Builder()
                            .target(new LatLng(arg0.getLatitude(), arg0.getLongitude()))      // Sets the center of the map to location user
                            .zoom(17)                   // Sets the zoom
                            //.bearing(90)                // Sets the orientation of the camera to east
                            //.tilt(40)                   // Sets the tilt of the camera to 30 degrees
                            .build();                   // Creates a CameraPosition from the builder
                    googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

                }
            });

        }
    }
}

@Override
protected void onResume() {
    super.onResume();
    initilizeMap();
}

}