I am designing an android app with Xamarin which will have an activity with google maps inside it, but i am struggling to display the map. It shows an empty box with no map display on it. Following is the code which i used for this practice.
My Activity
namespace teslin
{
[Activity(Label = "Map")]
public class MpActivity : Android.GoogleMaps.MapActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.MapView);
var map = FindViewById<MapView>(Resource.Id.mapv);
map.Clickable = true;
map.Controller.SetZoom(16);
map.Controller.SetCenter(new GeoPoint((int)40.8270449E6, (int)-73.9279148E6));
}}
xml lay out
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout3"
android:layout_weight="9" />
<com.google.android.maps.MapView
android:id="#+id/mapv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="true"
android:apiKey="AIzaSyD-UMij5IO6ezjuFCNnF7tRoG3niaPbNEU" />
</LinearLayout>
It looks like you're using the obsolete/outdated Maps API v1. Google removed support for this last year.
Instead you want to use Android Maps API v2 (a part of Google Play Services). Xamarin has some documentation on Maps in Android. It can be a bit tricky to get Maps working in Android, so carefully read these docs. Specifically, you'll want to read the section on the Maps API.
There is an example on Github that shows how to use the Google Play Services Component to add Maps to your application.
For those who are looking for a thorough example, check out this video that demonstrates how to integrate Google Maps with Xamarin Android, hope this helps!
Related
When i upload a relese to Google Play Console, after internal testing y have a warning (Accessibility => Content labeling) associated to this component.
<ImageButton .../>
Here the recomendation is use android:contentDescription
Then i add xmlns:android="http://schemas.android.com/apk/res/android"
and:
<ImageButton android:contentDescription="bla bla" .../>
But i get an error: The property contentDescription was not found in type ImageButton.
I try to use xct:SemanticEffect.Description and i have not compiler error but in Google Play Console i still see the warning.
More Information:
Full component code:
<ImageButton BackgroundColor="Transparent" Margin="5" xct:SemanticEffect.Description="abrir menú" Clicked="OnBackButtonClicked" >
<ImageButton.Source>
<FontImageSource FontFamily="FAL" Glyph="" Color="{StaticResource Gray3}" Size="25"/>
</ImageButton.Source>
</ImageButton>
Google Play Console - Pre-launch report details - Accesibility tab
Content labeling warning for this component
As already pointed out, you cannot add android:contentDescription="bla bla" directly to the ImageButton one is from the Android platform, the latter is on the Xamarin.Forms level.
If you use the Xamarin Community Toolkit and apply the SemanticEffect.Description="bla bla" that should translate into the contentDescription on Android. If that is not the case, I would be curious to know what the exact warning is that you get after applying it.
Hi Am working on google maps. i have added location in a fragment now am trying to add StreetViewPanoramaView to the fragment . But am getting Oops! something went wrong error message as shown in 2nd image
this is my code
maps_activity.xml
<Button
android:id="#+id/button_streetview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open StreetView"
/>
<androidx.fragment.app.FragmentContainerView
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MapsActivity" />
<com.google.android.gms.maps.StreetViewPanoramaView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/streetview"/>
This is my MapActivity.kt
button_streetview.setOnClickListener(View.OnClickListener {
var mStreetViewPanoramaView : StreetViewPanoramaView = findViewById(R.id.streetview)
mStreetViewPanoramaView.onCreate(savedInstanceState)
var streetViewPanorama: StreetViewPanoramaOptions = StreetViewPanoramaOptions()
streetViewPanorama.panningGesturesEnabled(false)
streetViewPanorama.position(address)
streetViewPanorama.userNavigationEnabled(false)
streetViewPanorama.zoomGesturesEnabled(true)
var streetViewPanoramaCamera : StreetViewPanoramaCamera = StreetViewPanoramaCamera(25F,30F,1F)
streetViewPanorama.panoramaCamera(streetViewPanoramaCamera)
mStreetViewPanoramaView = StreetViewPanoramaView(this,streetViewPanorama)
mStreetViewPanoramaView.getStreetViewPanoramaAsync(this)
})
i can successfully retrive latitude and longitude of a place by address and display it in infoWindow and add custom marker as shown in image.
But when i click openstreetview button error message is coming.
This is the StreetView
This is the logcat
As This Error message is showing Wrong API key but i have added correct Key as i can retrive and display a marker successfully. Can anyone please tell me where am doing wrong
It looks like you are getting the error described here:
If you receive an error such as Your card does not support automatic
recurring payments or General decline of the card, please select a
different form of payment.
You might encounter these errors if you are using a debit card that
requires two-factor authentication to complete an online transaction.
Two-factor authentication requires you to be in-session at the time of
the transaction. Cards that require you to be in-session are not
usable for subscriptions or similar recurring automatic transactions.
Your street view map should work without problem once you enable billing on your project. Hope this helps!
I want to show VR tour like this http://alfavr.ir/alfavr.ir/to/park.html in my Android app.
how can I do that?
I tried to display with web view because the file format is Html but did not work.
You can try with VRPanormaView which is included in the Google VR SDK. This is an example from https://developers.google.com/vr/develop/android/vrview:
<com.google.vr.sdk.widgets.pano.VrPanoramaView
android:id="#+id/pano_view"
android:layout_margin="5dip"
android:layout_width="match_parent"
android:scrollbars="#null"
android:layout_height="250dip" />
Inside the Activity, the primary method is VrPanoramaView.loadImageFromBitmap(). Call it with a standard Android Bitmap object and an optional VrPanoramaView.Options object. The latter is used to configure the format of the image. The Activity also implements a VrPanoramaEventListener which receives events when the load operation succeeds or fails.
Adding this line make It work.
webView.getSettings().setJavaScriptEnabled(true);
I have an existing Android Cordova project which uses an embedded WebView. What this means is that the Activity does not extend CordovaActivity, but instead embeds the SystemWebView and initializes within the onCreate.
The following is currently how this is being done:
Within the layout XML file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
.... other layout elements not related to Cordova....
<org.apache.cordova.engine.SystemWebView
android:id="#+id/cdvWebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
Within the Activity's onCreate:
SystemWebView systemWebView = (SystemWebView) findViewById(R.id.cdvWebView);
CordovaWebView cdvWebView = new CordovaWebViewImpl(new SystemWebViewEngine(systemWebView));
ConfigXmlParser parser = new ConfigXmlParser();
parser.parse(this);
cdvWebView.init(this, parser.getPluginEntries(), parser.getPreferences());
Due to the bug in Lollipop versions 5.0.+ missing the "set" button, I want to implement the Crosswalk plugin into the project.
Unfortunately, all the documentation I'm finding assumes that a typical Cordova install is being used. I haven't been able to get the embedding and initialization of the XWalkWebView working correctly and keep getting a blank white screen.
Has anybody has success with a similar scenario?
I'm not sure, but this might answer your question. It seems to show implementing an XWalkWebView outside of a typical cordova project:
https://github.com/kurli/crosswalk-website/wiki/How-to-use-Crosswalk-Embedded-API-on-Android
I am working on a project using Google Maps v2 for Android and I am getting a NoSuchFieldError while instantiating the Google map fragment on a rooted HTC Desire HD.
Afaik, the issue should not be caused by Google Play Services not being installed on the device (event though they are and other applications using Google Maps v2 are working).
I have tried making a check to see if Google Play Services library is installed on the device (by calling GooglePlayServicesUtil.isGooglePlayServicesAvailable) prior to setting the Activity's content view.
Furthermore, the application runs on other Android phones and the map fragment is successfully inflated.
At the moment I suspect that this issue is caused by my Android project setup in Eclipse, as the Google Play Services library project seems not to be included along with my project during packaging or deployment.
Has anyone had and solved this issue with Google Maps working only on some devices and throwing a NoSuchFieldError exception on others? If so, what can I do to solve this?
If you need more information such as project setup and/or code, please leave a comment.
Thank you!
This is the stack trace report from ACRA in JSON format:
{ CUSTOM_DATA: '',
STACK_TRACE: 'java.lang.NoSuchFieldError: com.google.android.gms.R$string.common_google_play_services_unsupported_text\n\tat com.google.android.gms.common.GooglePlayServicesUtil.b(Unknown Source)\n\tat com.google.android.gms.internal.bb.a(Unknown Source)\n\tat com.google.android.gms.internal.bb.onCreateView(Unknown Source)\n\tat com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)\n\tat android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)\n\tat android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)\n\tat android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)\n\tat android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)\n\tat android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)\n\tat android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)\n\tat android.view.LayoutInflater.rInflate(LayoutInflater.java)\n\tat android.view.LayoutInflater.inflate(LayoutInflater.java)\n\tat android.view.LayoutInflater.inflate(LayoutInflater.java)\n\tat android.view.LayoutInflater.inflate(LayoutInflater.java)\n\tat com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java)\n\tat android.app.Activity.setContentView(Activity.java)\n\tat ro.myapp.app.activities.MapActivity.onCreate(MapActivity.java:62)\n\tat android.app.Activity.performCreate(Activity.java)\n\tat android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)\n\tat android.app.ActivityThread.performLaunchActivity(ActivityThread.java)\n\tat android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)\n\tat android.app.ActivityThread.access$600(ActivityThread.java)\n\tat android.app.ActivityThread$H.handleMessage(ActivityThread.java)\n\tat android.os.Handler.dispatchMessage(Handler.java)\n\tat android.os.Looper.loop(Looper.java)\n\tat android.app.ActivityThread.main(ActivityThread.java)\n\tat java.lang.reflect.Method.invokeNative(Native Method)\n\tat java.lang.reflect.Method.invoke(Method.java)\n\tat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)\n\tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java)\n\tat dalvik.system.NativeStart.main(Native Method)\n',
PHONE_MODEL: 'HTC Desire HD',
ANDROID_VERSION: '4.0.4' }
This is my onCreate method throwing the exception:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
checkForPlayServices();
setContentView(R.layout.activity_map);
mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
map = mapFragment.getMap();
map.setMyLocationEnabled(true);
map.setInfoWindowAdapter(this);
map.setOnInfoWindowClickListener(this);
}
Contents of activity_map.xml layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapActivity" >
<ro.myapp.app.views.actionbar.ActionbarMap
android:id="#+id/actionBar"
android:layout_width="match_parent"
android:layout_height="#dimen/myapp_actionbar_height" />
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/actionBar"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
java.lang.NoSuchFieldError: com.google.android.gms.R$string.common_google_play_services_unsupported_text
says exactly what is the problem.
In values/strings.xml there is no
<string name="common_google_play_services_unsupported_text">...</string>
defined.
I see this value defined in my google-play-services_lib/res, so you may want to check if you correctly added this library project to your workspace. Seems like you have forgot to update strings.xml when updating library.
Ok so I changed my answer I found out there is a way to find out if there is anything overriding your libs.... You are using the Location Objects somewhere so add this bit of code and debug it when running one of those devices..... The location object should be in your location listener.
location.getClass().getProtectionDomain().getCodeSource().getLocation() ;