Adding a map to a class - google-maps

Hello I would like to add a map (static image) to a page. I will try to explain what I have done so far and what my problem is as good as I can in case someone else has the same problem in the future.
I have done the following:
1. Updated the Manifest file with permissions/API (got the API (from Google API Console) key using the SHA1 from Eclipse using Window > Preferences > Build
2. Updated the XML file of the class where the map will be added
3. Added some Java code into the classes Java file
Below is the Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.lapmaster"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/lapmaster_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="net.learn2develop.lapmaster.LapMasterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="Logged In"
android:name=".UserLoggedInScreen" >
<intent-filter >
<action android:name="net.learn2develop.UserLoggedInScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:label="Track Listing"
android:name=".ListOfCircuits" >
<intent-filter >
<action android:name="net.learn2develop.ListOfCircuits" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:label="Snetterton"
android:name=".Snetterton" >
<intent-filter >
<action android:name="net.learn2develop.Snetterton" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Other activities -->
<!-- Google Play Services -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Various" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</application>
</manifest>
Below is the class XML:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Below is the class Java:
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.SupportMapFragment;
public class Snetterton extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.snetterton);
SupportMapFragment map = ((SupportMapFragment)
.getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
}
}
As you can probably guess from my code I am creating an app for race tracks. In the class called Snetterton I want to add a picture (Google maps) of Snetterton.
To get to this page the user:
1. Starts at a login screen (LapMasterActivity)
2. Is greeted with a home page (UserLoggedInScreen)
3. Goes to a page with a list of tracks (for now it is just Snetterton) (ListOFTracks)
4. When the user clicks the button for Snetterton it takes them to the Snetterton class' page where I would like the map. (Snetterton).
In my code only ((SupportMapFragment) is underlined.
Thanks.

Answered this myself (eventually):
Code I used is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutFragment"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
public class TopGear extends Activity
{
private GoogleMap aMap;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.top_gear);
aMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
aMap.getUiSettings().setAllGesturesEnabled(false);
LatLng topGearTrack = new LatLng(51.116492, -0.541767);
aMap.setMyLocationEnabled(true);
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(topGearTrack, 15));
aMap.addMarker(new MarkerOptions()
.title("Top Gear")
.snippet("Welcome to the famous Top Gear circuit.")
.position(topGearTrack));
aMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
setUpMapIfNeeded();
}
public void setUpMapIfNeeded()
{
//Do a null check to confirm that we have not already instantiated the map.
if (aMap == null)
{
aMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
//Check if we were successful in obtaining the map.
if (aMap != null)
{
//The Map is verified. It is now safe to manipulate the map.
}
}
}
}

Related

Can't open .xlsx file from aspose cells if it wasn't created using aspose cells

So I'm working on an app for android and I've gotten it to work as long as it's been created using aspose cells. Here is my code:
class Home: Fragment(R.layout.fragment_home) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view: View = inflater.inflate(R.layout.fragment_home, container, false)
val load = view.findViewById<Button>(R.id.button3)
val new = view.findViewById<Button>(R.id.button4)
val editText = view.findViewById<EditText>(R.id.editTextTextPersonName)
new.setOnClickListener(View.OnClickListener {
Excel.name = "${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx"
Excel.workbook = Workbook()
Excel.workbook!!.save(Excel.name)
println("Created: ${Excel.workbook}")
})
load.setOnClickListener(View.OnClickListener {
Excel.workbook = Workbook("${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx")
Excel.name = "${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx"
Excel.workbook!!.save("${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx")
println("Loaded: ${Excel.workbook}")
})
return view
}
}
the problem is when I try to download a .xlsx file and load it, it gives me this error:
Caused by: java.io.FileNotFoundException: /storage/emulated/0/Download/ECR.xlsx: open failed: EACCES (Permission denied)
I'm not sure why this is happening. Any help would be awesome! Thanks!
EDIT:
Here's my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.FRCScout22"
tools:targetApi="31">
<activity
android:name=".DropDownActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>

Google Maps [API] view is gray on my mobile device

Hi guyes I really need your help.
I've read the instructions on how to use Google API on this link:
https://developers.google.com/maps/documentation/android/start
I've followed all seven steps but I couldn't display Google Map in my app.
[I have already got tired from trying to get the Emulator to work so I've decided to generate an APK file instead and send it to my smartphone]
After intalling the app, once I open it I can only see a grey screen and 'Google' signeture at the bottem left of the screen. that's all, nothing happens.
The app works fine when I connect my device and use the debug mode.
I've tried installing it Via the adb but it still didn't work.
I've been following many articles for the last three days regarding this issue but no matter what I've tried it just didn't work.
What am I doing wrong?
Here is my code:
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.googlemapslast" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIza**********"/>
</application>
</manifest>
Main Activity Java:
package josh.com.googlemap2;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap map) {
// Add a marker in Sydney, Australia, and move the camera.
LatLng sydney = new LatLng(-34, 151);
map.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
map.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
Main Activity Layout:
<fragment 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"
android:id="#+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Goole_Maps_api.xml
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
AIzaSyAnvkHr4CGYzmROT*******
</string>
</resources>
Alright, There are two things that you should note if you encounter a similar situation:
1) There are two google maps api.xml files, one for release and one for debug.
you can find them on these paths:
\app\src\release\res\values
\app\src\debug\res\values
Make sure to add your Google Map Key on both files!
2) I didn't find this information on official source but you need to generate another SHA1 key for the release file in addition to your regular SHA1 key.
You must have two SHA1 keys, one for the debug version and one for the release version.
Once you have the new key for the release file, add it to your Google API Console exisiting key at the second row.

"Error inflating class fragment" with google map on xamarin

I have xamarin for an android app. I would like an ActionBar with tabs and a google map on one tab.
It works but only one time when i click on the map tab.
I explain, the app launched, im on the event tab, i click on map tab, the map works correctly but when i go back to event tab and again map tab, it crash.
Main:
ActionBar.SetDisplayShowHomeEnabled (true);
ActionBar.SetDisplayShowHomeEnabled (true);
ActionBar.SetDisplayShowTitleEnabled (true);
ActionBar.SetTitle (Resource.String.app_name);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
SetContentView (Resource.Layout.Main);
var fragMap = new MapPageFragment();
ActionBar.Tab tab2 = ActionBar.NewTab();
tab2 = ActionBar.NewTab();
tab2.SetText("Map");
tab2.TabSelected += delegate(object sender, ActionBar.TabEventArgs e)
{
e.FragmentTransaction.Replace(Resource.Id.fragment_container, fragMap);
};
ActionBar.AddTab(tab2);
MapPageFragment:
namespace OnmappTest
{
public class MapPageFragment : Android.App.Fragment
{
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
view = inflater.Inflate(Resource.Layout.MapPage, container, false);
The error
binary xml file line #1: error inflating class fragment" on "view =
inflater.Inflate(Resource.Layout.MapPage, container, false);
MapPage
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="350dp"
class="com.google.android.gms.maps.MapFragment" />
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="OnmappTest.OnmappTest">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="21" />
<!-- Google Maps for Android v2 requires OpenGL ES v2 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<!-- We need to be able to download map tiles and access Google Play Services-->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allow the application to access Google web-based services. -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Google Maps for Android v2 will cache map tiles on external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:label="OnmappTest" android:icon="#drawable/icon">
<!-- Put your Google Maps V2 API Key here. -->
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="value" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</application>
I tried SupportMapFragment instead of MapFragment, FragmentActivity instead of Fragment but nothing
I had the same problem. Please add this to OnPause method:
protected override void OnPause()
{
base.OnPause();
if (_mapFragment != null)
{
FragmentManager fragmentManager = FragmentManager;
fragmentManager.BeginTransaction().Remove(_mapFragment).Commit();
}
}
This solved my problem, hope that will solve yours.

Package.appxmanifest not showing all 7 Tabs

I re-targeted my project from wp8 to wp8.1. At first my package.appxmanifest file's build action was not set to Appxmanifest. Also it is only showing 4 tabs
-Application
-capabilities
-Declarations
-Packaging
Tabs that are missing are
-Visual Assets
-content URI's
-Declarations
What should i do.
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
<Identity Name="37576f76-9ac9-4f78-b2d9-cb51446fb500" Publisher="CN=R" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="e4312153-3f4c-49dd-904d-5fbe8f1d6000" PhonePublisherId="3f72d71c-dd80-408e-affb-aa06372f300a" />
<Properties>
<DisplayName>app</DisplayName>
<PublisherDisplayName>app</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Prerequisites>
<OSMinVersion>6.3.1</OSMinVersion>
<OSMaxVersionTested>6.3.1</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="xe4312153y3f4cy49ddy904dy5fbe8f1d6073x" Executable="AGHost.exe" EntryPoint="MainPage.xaml">
<m3:VisualElements DisplayName="app" Square150x150Logo="Assets\SquareTile150x150.png" Square44x44Logo="Assets\Logo.png" Description="app" ForegroundText="light" BackgroundColor="#464646" ToastCapable="true">
<m3:DefaultTile Square71x71Logo="Assets\SquareTile71x71.png">
</m3:DefaultTile>
<m3:SplashScreen Image="SplashScreenImage.jpg" />
<m3:ApplicationView MinWidth="width320" />
<!--Used in XAML Designer. DO NOT REMOVE-->
</m3:VisualElements>
</Application>
</Applications>
<Extensions>
<Extension Category="windows.activatableClass.inProcessServer">
<InProcessServer>
<Path>AgHostSvcs.dll</Path>
<ActivatableClass ActivatableClassId="AgHost.BackgroundTask" ThreadingModel="both" />
</InProcessServer>
</Extension>
</Extensions>
<Capabilities>
<Capability Name="internetClientServer" />
<DeviceCapability Name="location" />
</Capabilities>
</Package>
Silverlight-based apps don't have those extra tabs; they are only applicable to non-Silverlight (WinRT) apps. You set things like your Tile icons via the WMAppManifest.xml file.

The description com.google.android.gms.play-services.4.2.42 is invalid

Android studio - googgle maps api v2 using these links:
https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2
Google Maps in Android Studio
messages gradle tasks:
A problem occurred evaluating project ':app'.
> The description com.google.android.gms.play-services.4.2.42 is invalid
Event log:
3:29:53 PM Gradle invocation completed successfully with 1 error(s) in 6 sec
3:29:56 PM Gradle 'MyApplication2' project refresh failed:
The description com.google.android.gms.play-services.4.2.42 is invalid
Gradle settings
in my build.gradle file
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 13
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard- rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms.play-services.4.2.42'
I found this version number from .....sdk\extras\google\google_play_services\libproject\google-play-services_lib\AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms"
android:versionCode="4242030"
android:versionName="4.2.42 (1018832-030)" >
<uses-sdk android:minSdkVersion="9"/>
</manifest>
and if it helps...manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="19" />
<permission
android:name="com.android.test.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.android.myapplication2.app.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key"/>
</application>
Instead of:
compile 'com.google.android.gms.play-services.4.2.42'
You need:
compile 'com.google.android.gms:play-services:4.2.42'