How To Get Rid Of Uber App On Google Maps
Implement google map like Uber
Problem:
I am completely new to android.I am trying to implement a draggable google map like uber app.I have found out a code from somewhere,But when I try running few issues were coming like
Error:(24, 37) error: cannot find symbol class GooglePlayServicesClient Error:(26, 39) error: cannot find symbol class LocationClient
In my dependencies I have added
compile 'com.google.android.gms:play-services:8.4.0'
Following is the code I have used.
package com.rakyow.taxifinder.taxifinder; import java.io.IOException; import java.util.List; import java.util.Locale; import android.app.Activity; import android.app.Dialog; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; import android.widget.TextView; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener { // A request to connect to Location Services private LocationRequest mLocationRequest; GoogleMap mGoogleMap; public static String ShopLat; public static String ShopPlaceId; public static String ShopLong; // Stores the current instantiation of the location client in this object private GoogleApiClient mLocationClient; boolean mUpdatesRequested = false; private TextView markerText; private LatLng center; private LinearLayout markerLayout; private Geocoder geocoder; private List<Address> addresses; private TextView Address; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.homepage); markerText = (TextView) findViewById(R.id.locationMarkertext); Address = (TextView) findViewById(R.id.adressText); markerLayout = (LinearLayout) findViewById(R.id.locationMarker); // Getting Google Play availability status int status = GooglePlayServicesUtil .isGooglePlayServicesAvailable(getBaseContext()); if (status != ConnectionResult.SUCCESS) { // Google Play Services are // not available int requestCode = 10; Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); dialog.show(); } else { // Google Play Services are available // Getting reference to the SupportMapFragment // Create a new global location parameters object mLocationRequest = LocationRequest.create(); /* * Set the update interval */ mLocationRequest.setInterval(GData.UPDATE_INTERVAL_IN_MILLISECONDS); // Use high accuracy mLocationRequest .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Set the interval ceiling to one minute mLocationRequest .setFastestInterval(GData.FAST_INTERVAL_CEILING_IN_MILLISECONDS); // Note that location updates are off until the user turns them on mUpdatesRequested = false; /* * Create a new location client, using the enclosing class to handle * callbacks. */ mLocationClient = new GoogleApiClient(this, this, this); mLocationClient.connect(); } } private void stupMap() { try { LatLng latLong; // TODO Auto-generated method stub mGoogleMap = ((MapFragment) getFragmentManager().findFragmentById( R.id.map)).getMap(); // Enabling MyLocation in Google Map mGoogleMap.setMyLocationEnabled(true); if (mLocationClient.getLastLocation() != null) { latLong = new LatLng(mLocationClient.getLastLocation() .getLatitude(), mLocationClient.getLastLocation() .getLongitude()); ShopLat = mLocationClient.getLastLocation().getLatitude() + ""; ShopLong = mLocationClient.getLastLocation().getLongitude() + ""; } else { latLong = new LatLng(12.9667, 77.5667); } CameraPosition cameraPosition = new CameraPosition.Builder() .target(latLong).zoom(19f).tilt(70).build(); mGoogleMap.setMyLocationEnabled(true); mGoogleMap.animateCamera(CameraUpdateFactory .newCameraPosition(cameraPosition)); // Clears all the existing markers mGoogleMap.clear(); mGoogleMap.setOnCameraChangeListener(new OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition arg0) { // TODO Auto-generated method stub center = mGoogleMap.getCameraPosition().target; markerText.setText(" Set your Location "); mGoogleMap.clear(); markerLayout.setVisibility(View.VISIBLE); try { new GetLocationAsync(center.latitude, center.longitude) .execute(); } catch (Exception e) { } } }); markerLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub try { LatLng latLng1 = new LatLng(center.latitude, center.longitude); Marker m = mGoogleMap.addMarker(new MarkerOptions() .position(latLng1) .title(" Set your Location ") .snippet("") .icon(BitmapDescriptorFactory .fromResource(R.drawable.add_marker))); m.setDraggable(true); markerLayout.setVisibility(View.GONE); } catch (Exception e) { } } }); } catch (Exception e) { e.printStackTrace(); } } @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onConnectionFailed(ConnectionResult arg0) { // TODO Auto-generated method stub } @Override public void onConnected(Bundle arg0) { // TODO Auto-generated method stub stupMap(); } @Override public void onConnectionSuspended(int i) { } @Override public void onDisconnected() { // TODO Auto-generated method stub } private class GetLocationAsync extends AsyncTask<String, Void, String> { // boolean duplicateResponse; double x, y; StringBuilder str; public GetLocationAsync(double latitude, double longitude) { // TODO Auto-generated constructor stub x = latitude; y = longitude; } @Override protected void onPreExecute() { Address.setText(" Getting location "); } @Override protected String doInBackground(String... params) { try { geocoder = new Geocoder(MainActivity.this, Locale.ENGLISH); addresses = geocoder.getFromLocation(x, y, 1); str = new StringBuilder(); if (geocoder.isPresent()) { Address returnAddress = addresses.get(0); String localityString = returnAddress.getLocality(); String city = returnAddress.getCountryName(); String region_code = returnAddress.getCountryCode(); String zipcode = returnAddress.getPostalCode(); str.append(localityString + ""); str.append(city + "" + region_code + ""); str.append(zipcode + ""); } else { } } catch (IOException e) { Log.e("tag", e.getMessage()); } return null; } @Override protected void onPostExecute(String result) { try { Address.setText(addresses.get(0).getAddressLine(0) + addresses.get(0).getAddressLine(1) + " "); } catch (Exception e) { e.printStackTrace(); } } @Override protected void onProgressUpdate(Void... values) { } } }
My requirement is something similar to this . Please help me in solving this issue.Any help would be appreciated. Thanks in advance
Solution:
I recommend that you use GoogleApiClient
because LocationClient is no longer supported in newer versions of play-services they removed it starting Google Play Services 6.5.87 if I am not mistaken. Here is the link for the example implementation. If you really want to use LocationClient, which I do not recommend, you can use an older version of the play-services
How To Get Rid Of Uber App On Google Maps
Source: https://tipsfordev.com/implement-google-map-like-uber
Posted by: bowlertheabsitters.blogspot.com
0 Response to "How To Get Rid Of Uber App On Google Maps"
Post a Comment