Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>How about using the newly introduced fused location provider</strong> as referenced from: <a href="http://developer.android.com/training/location/retrieve-current.html" rel="nofollow noreferrer">http://developer.android.com/training/location/retrieve-current.html</a></p> <pre><code>public static class XYZ extends Fragment implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener, LocationListener { GoogleMap map; LatLng latlng; private LocationRequest lr; private LocationClient lc; MapFragment mapFragment; ImageView iv; private static View view; public XYZ() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (view != null) { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) parent.removeView(view); } try { view = inflater.inflate(R.layout.XYZ, container, false); mapFragment = ((MapFragment) this.getActivity() .getFragmentManager().findFragmentById(R.id.map)); iv = (ImageView) view.findViewById(R.id.iv); map = mapFragment.getMap(); map.getUiSettings().setAllGesturesEnabled(false); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); map.getUiSettings().setZoomControlsEnabled(false); MapsInitializer.initialize(this.getActivity()); } catch (GooglePlayServicesNotAvailableException e) { Toast.makeText(getActivity(), "Google Play Services missing !", Toast.LENGTH_LONG).show(); } catch (InflateException e) { Toast.makeText(getActivity(), "Problems inflating the view !", Toast.LENGTH_LONG).show(); } catch (NullPointerException e) { Toast.makeText(getActivity(), "Google Play Services missing !", Toast.LENGTH_LONG).show(); } return view; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); lr = LocationRequest.create(); lr.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); lc = new LocationClient(this.getActivity().getApplicationContext(), this, this); lc.connect(); } @Override public void onLocationChanged(Location l2) { CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom( new LatLng(l2.getLatitude(), l2.getLongitude()), 15); map.animateCamera(cameraUpdate); } @Override public void onConnectionFailed(ConnectionResult arg0) { } @Override public void onConnected(Bundle connectionHint) { lc.requestLocationUpdates(lr, this); } @Override public void onDisconnected() { } } </code></pre> <p>With the XML as:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginBottom="4dp" android:layout_weight="1" &gt; &lt;fragment android:id="@+id/map" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; &lt;ImageView android:id="@+id/iv" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>You may get a blank map if you don't have all the requirements,</strong> <a href="https://developers.google.com/maps/documentation/android/start" rel="nofollow noreferrer">https://developers.google.com/maps/documentation/android/start</a></p> <ol> <li><p>Get Play services on your project by following this post <a href="https://blog-emildesign.rhcloud.com/?p=435" rel="nofollow noreferrer">https://blog-emildesign.rhcloud.com/?p=435</a></p></li> <li><p>Then get an api key: <a href="https://blog-emildesign.rhcloud.com/?p=403" rel="nofollow noreferrer">https://blog-emildesign.rhcloud.com/?p=403</a></p></li> <li><p>Add the permissions to you manifest,</p> <pre><code> &lt;uses-permission android:name="your.application.package.permission.MAPS_RECEIVE"/&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt; &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; </code></pre></li> <li><p>To test the map application you need to have a real device, if not then push play services to emulator via adb, read this post to learn how to install play services via adb <a href="https://stackoverflow.com/a/13869332/826657">https://stackoverflow.com/a/13869332/826657</a></p></li> <li><p>After all steps above, clean your project, uninstall the previous .apk from emulator, and run the project.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload