0

I am trying to build an arcgis nearby places android quite similar to this: https://developers.arcgis.com/example-apps/nearby-android/. I have make a map portal and import geojson file which placed all my stations location.

But i can't get the app to show my location.

package com.utbfyp.webmapapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.view.View;

import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.view.LocationDisplay;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.portal.Portal;
import com.esri.arcgisruntime.portal.PortalItem;

public class MainActivity extends AppCompatActivity {
    private MapView mv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mv = (MapView) findViewById(R.id.map1);

        LocationDisplay myLocation = mv.getLocationDisplay();
        myLocation.startAsync();

        //use ArcGIS Online as the Portal
        Portal arcgisOnline = new Portal("http://www.arcgis.com");
//create a PortalItem with ArcGIS Online WebMap ID
        PortalItem portalItem = new PortalItem(arcgisOnline, "xxxxx");
//create an ArcGISMap object with the PortalItem
        ArcGISMap myMap = new ArcGISMap(portalItem);
//display the webmap to MapView
        mv.setMap(myMap);

            }


        }
1

You need to check for location permissions and request permission if not granted:

Declare app permission in app manifest:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Check for the permission:

// define permission to request
String[] reqPermission = new String[] { Manifest.permission.ACCESS_FINE_LOCATION };

// get the MapView's LocationDisplay
myLocation = mv.getLocationDisplay();

// request permission at runtime
if (ContextCompat.checkSelfPermission(MainActivity.this, reqPermission[0]) == PackageManager.PERMISSION_GRANTED) {
  // Start Location Display
  myLocation.startAsync();
} else {
  // request permission
  ActivityCompat.requestPermissions(MainActivity.this, reqPermission, requestCode);
}

Additionally, you can check that your location display has started:

if (!myLocation.isStarted())
  myLocation.startAsync();
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.