Community

Topic: Geo Augmented Markers

Android - No Display a maps. (SOLVED)

Simone
Thursday, June 8, 2017

Hello,
I have completet the tutorial about Geo Augmented Markers to integrate your SDK in Android.

This is my code:

MainActivity.java


import android.location.Location;
import android.os.Bundle;
import com.pikkart.ar.geo.GeoElement;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends com.pikkart.ar.geo.GeoActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

private void init() {
//MyMarkerViewAdapter arMyMarkerViewAdapter = new MyMarkerViewAdapter(this, 51, 73);
//MyMarkerViewAdapter mapMyMarkerViewAdapter = new MyMarkerViewAdapter(this, 30, 43);
//InitGeoFragment(arMyMarkerViewAdapter, mapMyMarkerViewAdapter);

initGeoFragment();
Location loc1 = new Location("loc1");
loc1.setLatitude(44.652806);
loc1.setLongitude(10.912568);
List geoElementList = new ArrayList<>();

geoElementList.add(new GeoElement(loc1, "1", "Pikkart Headquarters"));
setGeoElements(geoElementList);
}
}


------

And code of "activity_main.xml :

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cellnexitalia.p_geo.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

---

Thanks in advance

user profile image
Support Team  (expert)
Friday, June 9, 2017

Hi,
our GeoActivity already has its own ContentView, so you do not have to call the setContentView method. If you want to use a custom view to show other contents over the activity you can use the addContentView method.
Best,

miguel
Wednesday, July 26, 2017

hi, i have the same problem, this is my code:

package com.pikkart.factoryim.pikkart_sdk_geo_tutorial;


import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.widget.Toast;
import com.pikkart.ar.geo.GeoElement;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends com.pikkart.ar.geo.GeoActivity {

private int m_permissionCode = 1234567890;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//if not Android 6+ run the app
if (Build.VERSION.SDK_INT < 23) {
init();
}
else {
checkPermissions(m_permissionCode);
}
}

private void checkPermissions(int code) {
String[] permissions_required = new String[] {
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION};
List permissions_not_granted_list = new ArrayList<>();
for (String permission : permissions_required) {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), permission) != PackageManager.PERMISSION_GRANTED) {
permissions_not_granted_list.add(permission);
}
}
if (permissions_not_granted_list.size() > 0) {
String[] permissions = new String[permissions_not_granted_list.size()];
permissions_not_granted_list.toArray(permissions);
ActivityCompat.requestPermissions(this, permissions, code);
}
else {
init();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if(requestCode==m_permissionCode) {
boolean ok = true;
for(int i=0;i<grantResults.length;++i) {
ok = ok && (grantResults[i]==PackageManager.PERMISSION_GRANTED);
}
if(ok) {
init();
}
else {
Toast.makeText(this, "Error: required permissions not granted!", Toast.LENGTH_SHORT).show();
finish();
}
}
}

private void init() {
//MyMarkerViewAdapter arMyMarkerViewAdapter = new MyMarkerViewAdapter(this, 51, 73);
// MyMarkerViewAdapter mapMyMarkerViewAdapter = new MyMarkerViewAdapter(this, 30, 43);
//InitGeoFragment(arMyMarkerViewAdapter, mapMyMarkerViewAdapter);
initGeoFragment();

Location loc1 = new Location("loc1");
loc1.setLatitude(44.652806);
loc1.setLongitude(10.912568);

Location loc2 = new Location("loc2");
loc2.setLatitude(54.652806);
loc2.setLongitude(20.912568);

Location loc3 = new Location("loc3");
loc3.setLatitude(64.652806);
loc3.setLongitude(30.912568);


List geoElementList = new ArrayList<>();
geoElementList.add(new GeoElement(loc1, "1", "Pikkart Headquarters"));
geoElementList.add(new GeoElement(loc2, "2", ""));
geoElementList.add(new GeoElement(loc3, "3", ""));
setGeoElements(geoElementList);
}
}

user profile image
Support Team  (expert)
Wednesday, July 26, 2017

Hi Miguel,
have you already verified that the google map key is correct on google api console?

miguel
Wednesday, July 26, 2017

Yes, seems like the problem is the android nougat version with permition of conections, can send a email compressed proyect?

miguel
Wednesday, July 26, 2017

I tried with android 5.0 worked although I do not know how to show the camera with the code

miguel
Thursday, July 27, 2017

In which cell phones the sdk was tested to operate the camera

user profile image
Support Team  (expert)
Monday, July 31, 2017

Hi, to show the camera the phone must have the following sensors:
- gyroscope
- accelerometer
- gravity
- magnetometer

If your phone does not have one of these sensors, the sdk only shows the map.
Best,

miguel
Tuesday, August 1, 2017

Good day, thanks for answering my question, the compatibility problem is the private int m_permissionCode = 1234567890, a 16 bit code must be used to work 2 ^ 16 = 65536; Int m_permissionCode = 65536 and will work on android 6 and 7

Amit
Thursday, August 3, 2017

Hi Team,

I followed all steps that was mentioned for GEO AUGMENTED MARKERS FOR ANDROID. But when I try to run my app shows nothing.
I am using Lenovo Z2 plus. Could you please help?

Following is my code:

using Android.App;

using Android.Widget;
using Android.OS;
using System.Collections.Generic;
using Android.Support.V7.App;
using Android.Content.PM;
using Android.Content;
using Android.Views;
using Com.Pikkart.AR.Geo;
using Android.Runtime;
using Android.Locations;
using Android.Support.V4.App;

namespace Pikkart
{
[Activity(Label = "Pikkart", MainLauncher = true, Icon = "@drawable/icon", ConfigurationChanges = Android.Content.PM.ConfigChanges.ScreenSize | Android.Content.PM.ConfigChanges.Orientation, Theme = "@style/MyTheme")]
public class MainActivity : Com.Pikkart.AR.Geo.GeoActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//if not Android 6+ run the app
if (Build.VERSION.SdkInt < BuildVersionCodes.M)
{
init();
}
else
{
checkPermissions(m_permissionCode);
}
}
private int m_permissionCode = 65536;
private void checkPermissions(int code)
{
string[] permissions_required = new string[]{
Android.Manifest.Permission.Camera,
Android.Manifest.Permission.WriteExternalStorage,
Android.Manifest.Permission.ReadExternalStorage,
Android.Manifest.Permission.AccessNetworkState,
Android.Manifest.Permission.AccessCoarseLocation,
Android.Manifest.Permission.AccessFineLocation};

List<string> permissions_not_granted_list = new List<string>();
foreach (string permission in permissions_required)
{
if (ActivityCompat.CheckSelfPermission(this, permission) != Android.Content.PM.Permission.Granted)
{
permissions_not_granted_list.Add(permission);
}
}
if (permissions_not_granted_list.Count > 0)
{
string[] permissions = new string[permissions_not_granted_list.Count];
permissions = permissions_not_granted_list.ToArray();
ActivityCompat.RequestPermissions(this, permissions, m_permissionCode);
}
else
{
init();
}
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
if (requestCode == m_permissionCode)
{
bool isGranted = true;
for (int i = 0; i < grantResults.Length; ++i)
{
isGranted = isGranted && (grantResults[i] == Permission.Granted);
}
if (isGranted)
{
init();
}
else
{
Toast.MakeText(this, "Error: required permissions not granted!", ToastLength.Short).Show();
Finish();
}
}
}
private void init()
{
MyMarkerViewAdapter arMyMarkerViewAdapter = new MyMarkerViewAdapter(this, 51, 73);
MyMarkerViewAdapter mapMyMarkerViewAdapter = new MyMarkerViewAdapter(this, 30, 43);
InitGeoFragment(arMyMarkerViewAdapter, mapMyMarkerViewAdapter);
//InitGeoFragment();

Location loc1 = new Location("loc1");
loc1.Latitude = 45.466019;
loc1.Longitude = 9.188020;

Location loc2 = new Location("loc2");
loc2.Latitude = 41.903598;
loc2.Longitude = 12.476896;

Location loc3 = new Location("loc3");
loc3.Latitude = 44.647225;
loc3.Longitude = 10.924819;

List<GeoElement> geoElementList = new List<GeoElement>();
geoElementList.Add(new GeoElement(loc1, "1", "Scala, Milano"));
geoElementList.Add(new GeoElement(loc2, "2", "Rione II Trevi, Roma"));
geoElementList.Add(new GeoElement(loc3, "3", "Modena, Circoscrizione 1"));

SetGeoElements(geoElementList);

}
public override void OnMapOrCameraClicked()
{
base.OnMapOrCameraClicked();
}
public override void OnGeolocationChanged(Location p0)
{
base.OnGeolocationChanged(p0);
}
public override void OnGeoElementClicked(GeoElement p0)
{
Toast.MakeText(this, p0.Name + " is there", ToastLength.Short).Show();
}
private class MyMarkerViewAdapter : MarkerViewAdapter
{
public MyMarkerViewAdapter(Context context, int width, int height) : base(context, width, height)
{
IsDefaultMarker = false;
}

public override View GetView(GeoElement p0)
{
ImageView imageView = (ImageView)MarkerView.FindViewById(Resource.Id.image);
imageView.SetImageResource(Resource.Drawable.map_marker_yellow);
imageView.Invalidate();
return MarkerView;
}

public override View GetSelectedView(GeoElement p0)
{
ImageView imageView = (ImageView)MarkerView.FindViewById(Resource.Id.image);
imageView.SetImageResource(Resource.Drawable.map_marker_blue);
imageView.Invalidate();
return MarkerView;
}
}
}
}


Amit
Thursday, August 3, 2017

Also I have given all required permissions. Following is my Manifest file.

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Pikkart.Pikkart" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<!--suppress UsesMinSdkAttributes-->
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<application android:label="Pikkart" android:name="android.app.Application" android:allowBackup="true" android:icon="@drawable/icon" android:debuggable="true">
tag: <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyA8HnPLSDXSlFDMvg0tG8lZcDnC-YgeV3c" /><activity android:configChanges="orientation|screenSize" android:icon="@drawable/icon" android:label="Pikkart" android:theme="@style/MyTheme" android:name="md5dd6fb753178a7f9e16bad2c50124836d.MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="2147483647" android:authorities="Pikkart.Pikkart.mono.MonoRuntimeProvider.__mono_init__" /><!--suppress ExportedReceiver--><receiver android:name="mono.android.Seppuku"><intent-filter><action android:name="mono.android.intent.action.SEPPUKU" /><category android:name="mono.android.intent.category.SEPPUKU.Pikkart.Pikkart" /></intent-filter></receiver><activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="false" /><meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /></application>
<uses-feature android:name="android.hardware.camera.autofocus" />
</manifest>

Sign in to add a comment