Xamarin.Forms Maps crashing app - google-maps

I'm having a hard time trying to show a map on my Xamarin Forms app. This is the error I get everytime I open the page with the map:
0x29 in System.Diagnostics.Debugger.Mono_UnhandledException_internal C#
0x1 in System.Diagnostics.Debugger.Mono_UnhandledException C#
0x6 in Android.Runtime.UncaughtExceptionHandler.UncaughtException at /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Runtime/UncaughtExceptionHandler.cs:35,4 C#
0x1C in Java.Lang.Thread.IUncaughtExceptionHandlerInvoker.n_UncaughtException_Ljava_lang_Thread_Ljava_lang_Throwable_ at /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.Thread.cs:221,5 C#
0x1D in object.28d67210-c8ee-4f17-9d83-36104107982d C#
This is the code for creating the page:
var topLayout = new StackLayout
{
Children =
{
new Map(MapSpan.FromCenterAndRadius(new Position(37,-122), Distance.FromMiles(0.3)))
{
IsShowingUser = true,
HeightRequest = 100,
VerticalOptions = LayoutOptions.FillAndExpand
}
}
};
var bottomLayout = new StackLayout { Children = { ... } }; //shortened for readability
Content = new StackLayout
{
Children = { topLayout, bottomLayout }
};
I'm saying the problem is the map, because if I change the "new Map" line for a Label, for instance, it works.
I'm instantiating the Maps FW as said here: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/maps/
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Xamarin.FormsMaps.Init(this, bundle);
LoadApplication(new FullHelp.App());
}

I tried your solution for Android, and yes it did throw an Exception.
In the Debug --> Exceptions dialog box, if you click the Thrown checkbox for Common Language Runtime Exceptions you will get a more meaningful description of the exception to be resolved.
The exception detail thrown is:
'Java.Lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:valu…'
Looking at your AndroidManifest.xml you have no keys defined / capabilities.
Refer to this link that will discuss how to configure your Xamarin.Forms application to handle Maps integration as you appear to be missing some things.
There is more detail on my other StackOverflow answer here that details how to create the API key for Andorid.

Hold short keys Ctrl+Alt+E to open Exceptions in Visual Studio.

Related

Cannot edit a feature layer when I start a session editing

I am developing a standalone app based on ArcGIS Engine, and when I starting a session editing with the code block below:
//Declare the Engine editor at the class level.
private IEngineEditor m_engineEditor = new EngineEditorClass();
private void StartEditing(IMapControl2 m_mapControl)
{
IMap map = m_mapControl.Map;
//If an edit session has already been started, exit.
if (m_engineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing)
return ;
//Start editing the workspace of the first feature layer found.
for (int layerCounter = 0; layerCounter <= map.LayerCount - 1; layerCounter++)
{
ILayer currentLayer = map.get_Layer(layerCounter);
if (currentLayer is IFeatureLayer)
{
IFeatureLayer featureLayer = currentLayer as IFeatureLayer;
IDataset dataset = featureLayer.FeatureClass as IDataset;
IWorkspace workspace = dataset.Workspace;
m_engineEditor.StartEditing(workspace, map);
((IEngineEditLayers)m_engineEditor).SetTargetLayer(featureLayer);
break;
}
}
}
An exception occurred with error code: HRESULT: 0x80004005 (E_FAIL)). Please help me
After asking Google and reading ArcGIS Engine documents. I found my SDE GeoDatabase does not allow editing data, because I turn off version manager of ArcGIS GeoDatabase. Turn on it and add some code to check feature layer is editable.
IEngineEditLayers m_engineLayersEditor = m_engineEditor as IEngineEditLayers;
if (!m_engineLayersEditor.IsEditable(featureLayer))
{
MessageBox.Show("Can not start editing. Because feature layer is not allow editing", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

How do I allow an MIME extension map in ASP.NET vNext?

Background
I have a piece of LESS code that needs to be compiled at runtime with Less.js -- it calculates some things via JavaScript -- so I can't use the task runner, etc.
In my index.html, I have:
<head>
...
<link rel="stylesheet/less" href="assets/less/DynamicHeight.less" />
...
<script type="text/javascript" src="lib/less/less.js"></script>
...
</head>
Problem
Less.js appears unable to find the file:
And when I try to access the file directly, I see:
Question
How can I add the configuration that will allow this less file to be downloaded? Am I still able to use web.config files with vNext, or do I need to do something with config.json instead?
Lead 1: Should I use Owin?
Thinking this might be the right path but I'm pretty unfamiliar.
I see a number of tutorials out there, such as K. Scott Allen's, which reference code such as:
public void Configuration(IAppBuilder app)
{
var options = new StaticFileOptions
{
ContentTypeProvider = new FileExtensionContentTypeProvider()
};
((FileExtensionContentTypeProvider)options.ContentTypeProvider).Mappings.Add(
new KeyValuePair<string, string>(".less", "text/css"));
app.UseStaticFiles(options);
}
However, it appears that in its current version, asp.net is looking for a signature of Configure(IApplicationBuilder app) instead.
The IApplicationBuilder class doesn't have a method along the lines of UseStaticFiles -- it only has a signature of IApplicationBuilder Use(Func<RequestDelegate, RequestDelegate> middleware).
I have a feeling that this is likely the right path to solve the issue -- I just can't find out how to propertly configure the IAppliationBuilder to map the MIME extension.
Okay, I believe I figured it out.
Step 1: Add the appropriate library for static files
In ASP.NET vNext, this is Microsoft.Aspnet.StaticFiles.
In your project.json file, add the following under "dependencies":
"Microsoft.AspNet.StaticFiles": "1.0.0-beta2"
This adds the static middleware method that you can use later.
Step 2: Configure the app to use Static Files
Add the using statement at the top:
using Microsoft.AspNet.StaticFiles;
At this point, the app.UseStaticFiles method will be available, so your Configure method can look as follows:
public void Configure(IApplicationBuilder app)
{
var options = new StaticFileOptions
{
ContentTypeProvider = new FileExtensionContentTypeProvider()
};
((FileExtensionContentTypeProvider)options.ContentTypeProvider).Mappings.Add(
new KeyValuePair<string, string>(".less", "text/css"));
app.UseStaticFiles(options);
}
And voila! I get text when browsing to .less files, and no more error is appearing from LessJS.
In .NET Core 1.0.1, SeanKileen answer is still good. The following is a simple code rewrite:
public void Configure(IApplicationBuilder app, ...)
var contentTypeProvider = new FileExtensionContentTypeProvider();
contentTypeProvider.Mappings[".map"] = "application/javascript";
contentTypeProvider.Mappings[".less"] = "text/css";
app.UseStaticFiles(new StaticFileOptions()
{
ContentTypeProvider = contentTypeProvider
});
The above code EXTENDS the default mapping list (see the source), which already has ~370 mappings.
Avoid using the FileExtensionContentTypeProvider constructor overload that takes a dictionary (as suggested by JHo) if you want those 370 default mappings.
SeanKilleen's answer is right on, and still works ASP.NET Core RC1. My only improvement is to write the exact same code using collection initializers to make it cleaner.
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
{
{ ".less", "text/css" },
{ ".babylon", "text/json" },
// ....
})
});

Uri to open third party apps for wp8

I tried to create an app that opens some third party apps with the help of its Uri from a Tile. Well, it actually works in opening the third party apps but the problem is, first it launches my app(i.e MainPage is visible for a second) and then only it opens the respective app. Is there any way to make my app's MainPage invisible before opening an app or am i missing anything in Capabilities?
Here is my code :
IconicTileData iconicTileData1 = new IconicTileData();
iconicTileData1.Title = name;
iconicTileData1.SmallIconImage = new Uri("/Icons/Small.png", UriKind.Relative);
iconicTileData1.IconImage = new Uri("/Icons/Metro/" + name + "Medium.png", UriKind.Relative);
IconicTileData iconicTileData2 = iconicTileData1;
Uri navigationUri = new Uri("/MainPage.xaml?target=ms-settings-bluetooth:", UriKind.Relative);
ShellTile.Create(navigationUri, (ShellTileData)iconicTileData2, true);
Thanks in advance for your help.
You could try to specify a "custom" page target (instead of MainPage.xaml) and then make a UriMapper that will allow your app to redirect. Here is a nice blog post on creating a UriMapper. Here is some pseudo-code to help:
public class SettingsUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
if (uri.OriginalString.StartsWith == "/LaunchSettings.xaml")
{
// parse which settings to go to
// launch settings uri
}
return uri;
}
}

Issue with CDialog::DoModal() when called from firebreath plugin

I have my ActiveX COM component developed in VC6. I have created the firebreath plugin over it to be able to call the COM API from different browsers. I have one API in ActiveX component which pops up the CDialog UI, On Google Chrome browser dlg.DoModal() function is failing. Issue is only with Chrome it simply crashes at this call, in other browsers its working perfectly
On Windows 7 its working with Google Chrome as well issue is with Windows XP.
Please provide me some feedback on this issue.
I am attaching some code snippets here to give some idea of what I am trying to do
Firebreath Plugin code (Plugin name is FBTest):
bool FBTest::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow *piw)
{
// The window is attached; act appropriately
try {
/* Now that we have the plugin window, create the ActiveX container
window as a child of the plugin, then create the ActiveX control
as a child of the container.
*/
FB::PluginWindowWin* pwnd = piw->get_as<FB::PluginWindowWin>();
if(pwnd != NULL)
{
HWND hWnd = pwnd->getHWND();
if(hWnd)
{
// Create the ActiveX control container
RECT rc;
::GetClientRect(hWnd, &rc);
m_fbTestWin.Create(hWnd, &rc, 0, WS_VISIBLE|WS_CHILD);
CComPtr<IUnknown> spControlTest;
//ETESTPROGID is prog id of activex component
HRESULT hrTest = m_fbTestWin.CreateControlEx(ETESTPROGID, NULL, NULL, &spControlTest, GUID_NULL, NULL);
if(SUCCEEDED(hrTest) && (spControlTest != NULL))
{
spControlTest.QueryInterface(&m_eTestAxCtl);
g_eTestAxCtl = m_eTestAxCtl;
if (m_eTestAxCtl)
{
//TODO: should we throw a FB exception here?
}
}
}
}
} catch(...) {
//TODO: should we throw a FB exception here?
}
return false;
}
void FBTest::TestFunc()
{
//hThread = (HANDLE)_beginthreadex(NULL, 0,&FBTest::Start, (void*)&m_eTestAxCtl, 0, &ThreadId);
if(m_eTestAxCtl)
{
try {
long nCode = -1;
//This is call to API of Activex component which will popup the dialog
HRESULT hr = m_eTestAxCtl->TestFunc();
//return nCode;
}
catch(...) {
}
}
}
Activex Component code :
STDMETHODIMP CTest::TestFunc()
{
//CTestDlg is ATL Dialog Object
CTestDlg TestDlg;
//At this call Google chrome is crashing
if(!TestDlg.DoModal())
return S_FALSE;
return S_OK;
}
I am calling TestFunc() API of plugin from one HTML page and its showing me the dailog in IE and firefox browsers but Chrome is crashing..
Please help.
Since you've given no info on when or how you're calling it, it's hard to be sure, but my guess is that you're calling DoModal on the main thread. That will cause the main thread to block.
You must never block the main thread in a plugin.
Try calling it on a different thread.

Blackberry: Passing KML file to Google Maps

I want to know that can I pass KML as a string to google map application?
Code snippet:
//KML String
String document = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><Folder><name>Paths</name><open>0</open><Placemark><LineString><tessellate>1</tessellate><coordinates> -112.0814237830345,36.10677870477137,0 -112.0870267752693,36.0905099328766,0</coordinates></LineString></Placemark></Folder></Document></kml>";
//Invoke Google Maps
int module = CodeModuleManager.getModuleHandle("GoogleMaps");
if (module == 0) {
try {
throw new ApplicationManagerException("GoogleMaps isn't installed");
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
}
}
String[] args = {document}; //Is this possible???
ApplicationDescriptor descriptor = CodeModuleManager.getApplicationDescriptors(module)[0];
ApplicationDescriptor ad2 = new ApplicationDescriptor(descriptor, args);
try {
ApplicationManager.getApplicationManager().runApplication(ad2, true);
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
}
After much R&D...the answer that I found out was that - No, we cannot pass KML as string.
Google Maps Mobile accepts a URL parameter. This needs to be in the form of "http://" and could be either specific parameters (such as "http://gmm/x?....") or a KML file ("http://..../sample.kml").
You MUST parse your mapFile (KML, gpx, txt) IF using the GoogleMaps API.
if all you want is to see your KML file inside a googlemaps window, you can goto the standard http://www.googlemaps.com and inside the ADDRESS box, you put the complete http address of your kml file.
until april2012 this used to work perfectly and the sidebar would be populated correctly, with clickable items (clicking on sidebar entry [e.g. "point 1" would fly-to the equivalent location). as of may2012, this feature is working incorrectly.
IF you want to take things one step further, you can have a PHP page echo the kml (on the fly KML rendering from database or file). BUT, googlemaps will not refresh your dynamically generated output for 10 to 15 minutes.
PM me if you want some javascript GPX and TXT mapFile rendering for GoogleMaps API vs3