Hie, im new in using arcgis in Android to display map on Android phone.
I manage to display the map on the Android phone, however , i am having difficulties to show the current location.
As in,at your current location, it would display a small blue dot.
Do you guys know how to show your current location using arcgis ?
Thanks in advance.
All you need to do it get the MapView's LocationService and call start() on it. But you need to do it after the map has been initialized. Here's a simple way to do that in your Activity's onCreate method (assuming your MapView is named map):
map = (MapView) findViewById(R.id.map);
map.setOnStatusChangedListener(new OnStatusChangedListener() {
#Override
public void onStatusChanged(Object source, STATUS status) {
if (STATUS.INITIALIZED == status) {
map.getLocationService().start();
}
}
});
//Then add layers to the map
Related
I am trying to implement the ad in my app with Custom Native Ad Format - https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/custom-formats#java_1
So, according to the documentation I am going with the approach described there and creating the ad
...
private void setListeners() {
...
imageView.setOnClickListener(v -> {
nativeCustomFormatAd.performClick("IMAGE");
});
...
}
private NativeCustomFormatAd nativeCustomFormatAd;
AdLoader adLoader = new AdLoader.Builder(context, "/6499/example/native")
.forCustomFormatAd("10063170",
new NativeCustomFormatAd.OnCustomFormatAdLoadedListener() {
#Override
public void onCustomFormatAdLoaded(NativeCustomFormatAd ad) {
// Show the custom format and record an impression.
nativeCustomFormatAd = ad;
Drawable drawable = vm.nativeCustomFormatAd.getImage("IMAGE").getDrawable();
imageView.setDrawable(drawable);
}
},
new NativeCustomFormatAd.OnCustomClickListener() {
#Override
public void onCustomClick(NativeCustomFormatAd ad, String s) {
// Handle the click action
}
})
.withAdListener( ... )
.withNativeAdOptions( ... )
.build();
#SuppressLint("VisibleForTests")
AdManagerAdRequest adManagerAdRequest = new AdManagerAdRequest.Builder().build();
adLoader.loadAd(adManagerAdRequest);
...
So, it looks pretty simple I try to make a request for the ad then I got (in a callback) NativeCustomFormatAd, save it as a class member, and along with it get drawable and set it to the imageView (to present it in the UI). Once a user clicks on the imageView I get an event in the click listener and invoke nativeCustomFormatAd.performClick("IMAGE");.
The problem is that I expect that once I transfer the ad click to the SDK (by nativeCustomFormatAd.performClick("IMAGE");) SDK is supposed to open the external browser, but instead nothing happens.
P.S. I am sure that nativeCustomFormatAd.performClick("IMAGE"); getting invoked and also I see that SDK gets the click as I got a callback event here:
...
new NativeCustomFormatAd.OnCustomClickListener() {
#Override
public void onCustomClick(NativeCustomFormatAd ad, String s) {
// Handle the click action
}
})
...
What am I missing here?
According to the docs you linked:
When a click is performed on a custom format ad, there are three possible responses from the SDK, attempted in this order:
Invoke the OnCustomClickListener from AdLoader, if one was provided.
For each of the ad's deep link URLs, attempt to locate a content resolver and start the first one that resolves.
Open a browser and navigate to the ad's traditional Destination URL.
Also:
If you pass a listener object in, the SDK instead invokes its onCustomClick method and takes no further action.
Therefore, it seems you have to pass a null OnCustomClickListener.
I am using the new Google Places SDK: AutocompleteSupportFragment.
whenever i select an address from the result list it doesn't save it and show it on the field.
I am not sure why.
this is my code below:
i declaed the variable at the top of the class:
Place shipAddress;
and called this method where i needed:
final AutocompleteSupportFragment editAddress = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
editAddress.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
editAddress.setOnPlaceSelectedListener(new PlaceSelectionListener() {
#Override
public void onPlaceSelected(Place place) {
shipAddress = place;
}
#Override
public void onError(Status status) {
Log.e("ERROR", status.getStatusMessage());
}
});
i am also using the result in another method calling:
address = shipAddress.getAddress().toString();
but finally i get an error that
variable address is invoked on a null object.
Places SDK has been Depricated You need to migrate to new PLACES
API.. You can find solution by below guideline.
https://stackoverflow.com/a/55045772/10579969
Official page https://developers.google.com/places/android-sdk/client-migration#place_picker
I am currently building an android app in android studio and am unable to make street names appear for the region of interest (Stepanakert, Nagorno-Karabakh). I believe that street names exist for this region because they are visible on google maps. I know that I have enabled street names in the java code because they are visible in other regions from within my app. The relevent code that I am using is as follows:
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback {
private GoogleMap mMap;
LatLng stepanakert = new LatLng(39.8177000, 46.7528000);
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(stepanakert,13));
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
I am in need of help making the street names appear in Stepanakert. My hypothesis is that there is a disconnect between the map info that I am using from the google map api thing in the app and the information which is actually available to the public through google maps. See the below pictures to further understand my problem:
[
You can style your map with GoogleMap.setMapStyle() method and change how to show street name's and other attributes by passing JSON style file to it:
try {
// Customise the styling of the base map using a JSON object defined
// in a raw resource file.
boolean success = mMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
this, R.raw.style_json));
if (!success) {
Log.e("MapsActivityRaw", "Style parsing failed.");
}
} catch (Resources.NotFoundException e) {
Log.e("MapsActivityRaw", "Can't find style.", e);
}
You can create your custom style and get json file from the following Link https://mapstyle.withgoogle.com/
Put the json file in /res/raw/style_json.json
I'm working on a big application and I have to take the player's rank from the Google Play services' leaderboard. The leaderboard works well. I've already found the right method but I don't know how I'm supposed to use it:
private void loadRankOfLeaderBoard() {
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient, getResources().getString(R.string.leaderboard_leaderboard), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
#Override
public void onResult(final Leaderboards.LoadPlayerScoreResult scoreResult) {
if (isScoreResultValid(scoreResult)) {
rank = (int)scoreResult.getScore().getRank();
}
}
});
}
But the onResult callback is never called. Where am I supposed to call the function loadRankOfLeaderBoard?? I tried to put it in the onCreate and in the onActivityResult...
Thanks for your help!
Okay, I finnaly found solution ... here for curious
So if you have the same problem, you have to put the function loadRankOfLeaderBoard on the function "onConnected" which will be call when you connect your device at google play service.
I need to develop an app for android for a university task and a part of it consists in sending the GPS coords of the device to my database. Here's the class that I'm using to get the coords
public class MyLocationListener implements LocationListener {
double latitude;
double longitude;
public MyLocationListener(Context myContext){
LocationManager locationManager = (LocationManager) myContext.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
public double getLatitude(){
return latitude; }
public double getLongitude(){
return longitude; }
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
latitude = location.getLatitude();
longitude = location.getLongitude();
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
That is called inside InterfaceActivity.java, using this:
MyLocationListener ggwp = new MyLocationListener(InterfaceActivity.this);
HttpDevices elenco = new HttpDevices(LoginIstance.getIst().getLog()[0],LoginIstance.getIst().getLog()[1],LoginIstance.getIst().getID(),String.valueOf(ggwp.getLatitude()),String.valueOf(ggwp.getLongitude()));
And finally HttpDevices is an asynttask that "runs" http messages to my database, using this code:
HttpPost httppost = new HttpPost("http://88.116.86.82/android/remote/connessione.php?user="+usr+"&pass="+pss+"&id="+id+"&lat="+lat+"&long="+log);
But the coords send to the database are always 0.0 - 0.0 , and I can't even try the code an debug it on the emulator ( blue stack ) because it doesn't have gps coords. Tried it on my Moto G but they are just 0. I tried spamming that string (connessione.php etc.. ) in my broweser giving random values for lat and long and yes, it works. It updates the database and shows the coords in my app, so the problem should be in the java. Any tips? I've searched alot in google/stackoverflow and didnt' find anything, it's the first time I encouter a problem that requires me to post here. Hope you can help me! Thank youu!
Edit: in case you want to take a look at my whole code there is a github link:
https://github.com/leejaku/RemoteAndroid2
I just try to get through your code... Please correct me if I have missed something
If I look at your HttpDevices Class you try to send your Data like this...
lat = String.valueOf(MyLocationListener.latitude);
log = String.valueOf(MyLocationListener.longitude);
This will try to get the value of a class property which is 0.0, because it is not the instance of MyLocationListener that is updating the lat and long... you need to create a Singleton of MyLocationListener to get one single sharedInstance of your listener, or you have to do it with a Delegate Pattern, or you save the Values to SharedPreferences...
Do you have enough knowledge of Java to build one of these Paradigms, and does it make sense to you? (Sorry for that Question, I don't know how good you are mate :-)...) Otherwise I could write you something to solve it
UPDATE
Well this problem seems to be nasty, so we will need a "NastyLocationListener" to solve it, and thank Neo has written the ultimate one ;-)
Checkout this Class
https://gist.github.com/DennisWeidmann/de2ebb2b2549a938fa50
Usage just like this
/////////Just to know it
Log.e("lati", NastyLocationListener.getLatitude(this)); //On most phones you can use the Listener without any other Code
Log.e("longi", NastyLocationListener.getLongitude(this)); //It uses Androids native cached location but this is not updated proper
/////////Just to know it end
/////////Normal usage
nastyLocationListener = new NastyLocationListener(this); //In your MainActivity instanciate a NastyLocationListener (its only needed once... All other Activities could get data from him)
nastyLocationListener.startListening(); //It starts listening to Location Updates and triggers the Location Provider to fetch updates (its bool, true if almost one Provider is available, false if no Provider is available)
nastyLocationListener.stopListening(); //Use this line when you pause the app, or quit it... it will stop the listener and could be resumed with startListening()
NastyLocationListener.getLatitude(this); //Could be used in every class, on every time, however you want without any other code like above
NastyLocationListener.getLongitude(this); //Could be used in every class, on every time, however you want without any other code like above
/////////Normal usage end
UPDATE
Screenshot of your App on my device without changing any code instead of the REST Call, I have inserted a Log to output my Latitude..
Try with this class, it's from my github account: https://github.com/chiiiky14/GPStracker
Import it to your project and create the object:
GPSTracker gpstracker = new GPSTracker(context);
And after that:
gpstracker.getLatitude();
gpstracker.getLongitude();
Just make sure the GPS of your device is already activate. Hope this will help.