Why is my google maps v2 map pixelated? - android

I'm making an app with Google Maps API V2, but the map appears to be very low quality. When I open the Google Maps app on the same phone, the quality is much higher. Is there some configuration option that I need to set? This is my code:
GoogleMapOptions options = new GoogleMapOptions();
options.tiltGesturesEnabled(false);
options.rotateGesturesEnabled(false);
mapFragment = MapFragment.newInstance(options);
android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.map_holder, mapFragment);
ft.commit();
This is the layout:
<RelativeLayout
android:id="#+id/map_holder"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent">
<ImageView
android:src="#drawable/map_pin"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="24dp" />
</RelativeLayout>

Related

SupportMapFragment not showing Google Logo

I am using SupportMapFragment to display Google Maps in my app:
SupportMapFragment mMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG);
if (mMapFragment == null) {
mMapFragment = new SupportMapFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.map_frame, mMapFragment, MAP_FRAGMENT_TAG).commit();
}
mMapFragment.getMapAsync(this);
This is the xml part:
<FrameLayout
android:id="#+id/map_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/button_status_view">
</FrameLayout>
Unfortunately, the map doesn't show the Google logo which causes violation on the Google Maps APIs terms of service (https://developers.google.com/maps/terms) In particular clause 9.4(a), which does not allow developers to delete or alter the Google logo on the map displayed in your app.
How can I add the Google logo to the map? Should it be there by default? Am I missing something? The fragment currently shows only the GPS button.
use MapFragment instead of Frame Layout:
<fragment android:id="#+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.googlemapdemo.MapsActivity"/>

Is it possible to display google Map in android wear device using Google Maps Android API v2?

I would like to display google map in Android wear device using Google Maps Android API v2.
I can access to google play service and get the available status. However, I got NullPointerException error after the code mGoogleMap = fragment.getMap();
// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available
....
}else { // Google Play Services are available
// Getting reference to the SupportMapFragment
SupportMapFragment fragment = ( SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Getting Google Map
mGoogleMap = fragment.getMap();}
My layout file is as follows:
<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=".MyActivity" >
<fragment
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.SupportMapFragment" />

Android SupportFragment returns Map Object as null

I am displaying a map in my android application like this:
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
The fragment is defined like this:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraTargetLat="28.635308"
map:cameraTargetLng="77.224960"
map:uiCompass="true"
map:uiRotateGestures="true"
map:uiScrollGestures="true"
map:uiTiltGestures="true"
map:uiZoomControls="true"
map:uiZoomGestures="true"/>
The problem is on some mobiles it is working fine while on others(android 2.2,2.3) it is not working. The map object is null in these cases.
To me it appears that the reason behind this is that google play services is not installed on these mobiles. Am i correct, if yes what is the possible workaround.

Google maps v2 on android devices with minSDK below 11

i have problem with this line when I create project which use Google maps API v2.
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
It's says that I need to set minSDK to be minimum 11, but I want to use this application also on devices with android minSDK 8 (2.3.3). Any ideas? Or simply: How I can set google maps API v2 to be compatible with devices with minSDK 8.
Thanks
Use SupportMapFragment from a FragmentActivity, instead of MapFragment from an Activity. To use fragments on devices older than API Level 11, you need to use the Android Support package's backport of fragments (where FragmentActivity comes from).
http://android-er.blogspot.de/2012/12/using-supportmapfragment.html - small example
<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=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world" />
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
AND:
package de.meinprospekt.android.ui;
import java.text.SimpleDateFormat;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Fragment fragment = getSupportFragmentManager().findFragmentById(
R.id.map);
SupportMapFragment mapFragment = (SupportMapFragment) fragment;
GoogleMap mMap = mapFragment.getMap();

GoogleMap class object throw Nullpointer Exception

friends, I am getting NullPointer error ,on addMarker()
Below is my sample code.
GoogleMap myMap;
android.support.v4.app.FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment myMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = myMapFragment.getMap();
myMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
myMap.setMyLocationEnabled(true);
myMap.getUiSettings().setZoomControlsEnabled(true);
myMap.getUiSettings().setCompassEnabled(true);
myMap.getUiSettings().setMyLocationButtonEnabled(true);
Error message like NullPointer at line
myMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
tools:context=".DemoMapActiviy" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>
any idea how can i solve it?
I went through this issue a while back. First check to see if your fragment is found by the fragment manager.
If not try replacing the way you've put your fragment into your view. If you want an example of another way I've posted a maps example here
Any more questions feel free to comment and I'll work through it with you :)
EDIT
have you got the correct API key in there? If you can't contact Google's servers then there's a good chance that that's your problem. Otherwise may be a manifest issue make sure you have READ_GSERVICES and INTERNET permissions.
See Google Maps API V2 'Failed to Load Map. Could not contact Google Servers'
Edit 2
Ok so I was being lazy before and just referring you to my project. If you were getting a connection to maps in your project lets start from there.
What I was suggesting in my original response was to check and see if myMapFragment was null. If it is great try doing something along the lines of the following:
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
SupportMapFragment myMapFragment = new SupportMapFragment();
ft.replace(R.id.map, myMapFragment, Constant.TAXI_FRAGMENT_ID);
ft.commit();
Where R.id.map is an empty FrameLayout
If myMapFragment isn't null then try extending SupportMapFragment and running the following test:
public class MyMapFragment extends SupportMapFragment {
#Override
public void onActivityCreated()
{
if (getMap() == null) Log.e("TAG", "There's something very wrong here";
}
}
Also if you do this make sure that you are inflating an instance of MyMapFragment not of SupportMapFragment

Categories

Resources