Android - Maps Cannot show - android

i wanna show google maps on my android application. show i do some basic step like this :
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
maps.xml
<view android:id="#+id/mv"
class="com.google.android.maps.MapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:apiKey="0cNoErXkpZDlKvCYr_OFj5xZD39-***********"
/>
and this is may maps class, import and onCreate method
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.os.Bundle;
method onCreate() on maps class
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.maps);
mapView = (MapView)findViewById(R.id.mv);
mapView.setSatellite(false);
mapView.setTraffic(false);
mapView.setBuiltInZoomControls(true);
int maxZoom = mapView.getMaxZoomLevel();
int initZoom = maxZoom-2;
mapControl = mapView.getController();
mapControl.setZoom(initZoom);
latE6 = (int) (lat*1e6);
lonE6 = (int) (lon*1e6);
gp = new GeoPoint(latE6, lonE6);
mapControl.animateTo(gp);
overlayButton = (Button)findViewById(R.id.doOverlay);
but why my map didnt show, i only see the grid whithout maps, and when i try to read logcat, i see this error with yellow color
Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher#40563470
please help me. thanks mate

Are you sure your API key is correct? When the API key doesn't match, it shows the grid instead of the map.
Running the app from Eclipse directly on the emulator / an actual phone requires a different key then when you build the .apk file first and run that on a device.

-If you have internet over proxy you will get grids .
-Use the default debug keystore for generating API key and try .

Related

Can't access the main window/layout from my Activity

This is the start of a simple app to initially display some TextViews and Buttons.
I want to avoid using layout managers by getting the dimensions of the main window/layout and using that to hard-code the components any way I want.
But my main Activity can't get non-zero data about the main window/layout.
I don't know if it's supposed to be this way or if I'm doing something dumb, and would appreciate some help.
This is a command line project using Ant under win10 and outputting to a USB'd phone.
I've updated the SDK Manager to Android 6.0 (API 23) with Android Tools 24.4.1 and installed v23.2 of the Android Support Lib, although Ant seems to think differently as you can see in my previous message which has the Ant output:
-build-setup:
[getbuildtools] Using latest Build Tools: 21.1.2.
I don't know if that makes a difference, but not in this case I think.
The next two files are complete as far as they go.
I would have included more but the way the website mangles my code doesn't encourage uploading to it.
It might have helped if I could have comprehended the 'How to Format' but (A) I didn't even see it before my first post and (B) I don't understand it now.
There are far too many instructions and too much jargon; e.g. what is a backtick?
Can't there be a simple format that will take everything you throw at it?
main.xml
========
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
package="com.Chatterton.Peter.ChessClock"
android:id="#+id/main_window"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="#+id/time_text_view_left"
android:text="top_left"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Button
android:layout_alignParentBottom="true"
...
There are a total of 4 components, one per corner, with the same layout_width and height.
ChessClockActivity.java
=======================
package com.Chatterton.Peter.ChessClock;
import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;
import android.graphics.Color;
import android.widget.TextView;
import android.util.Log;
public class ChessClockActivity extends Activity
{
public int winOriginX=10, winOriginY=20, winWidth=44, winHeight=66;
#Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout mainLayout = (RelativeLayout)findViewById( R.id.main_window );
int mainWidth = mainLayout.getWidth();
int mainHeight = mainLayout.getHeight();
Log.d( "clox", "mainLayout=" + mainLayout );
Log.d( "clox", "main W/H=" + mainWidth + "/" + mainWidth );
...
Screen Results:
It shows the last component displayed -- full-size -- with its text.
logcat results:
===============
D:\Android\ChessClock>adb shell
shell#android:/ $ logcat clox:D *:S
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
D/clox (27214): mainLayout=android.widget.RelativeLayout#41755b80
D/clox (27214): main W/H=0/0
**
They have no size at this point of the initialization process.
Click here to an answer that will let you access the sizes of your components after they have been displayed.
Or perhaps you can get the window size and figure the placement of your components by that value......
Answer here

Google map not displaying some landmarks in android

I am new to android and working on an application which display Google map. So I followed the steps for loading google map in my application and it worked successfully but the map shown in my app is not displaying some of the landmarks, which are usually displayed in Google map app.
For more explanation, the map in my application is displaying college
library, main driveway, Children’s Park near my location but it is not
displaying the college name,or similarly it is displaying street
numbers and road names but not displaying any of the restaurants,bars
or any business landmarks.
The xml code:
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
The java code :
package com.example.mapprototype;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
Google play service and google map api key are added in manifest file.
<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="my_api_key"/>
Do I need to add something else to display all the landmarks like bars,restaurant,colleges etc. that are displayed in google map default application .
Such minor details are not included in the Google Maps API.
However you can fetch nearby places using the Places API and make your own markers on the map.
Further readings:
Google Places API documentation
Usage example by Tutsplus

error in findViewById

Hi I'm doing an android gps tutorial and I'm getting an error I don't understand (I'm pretty new to android dev). Im getting the error at
position = (WebView) findViewById(R.id.activity_main);
where activity_main seems to be the problem. Could somebody explain what the problem is? thanks.
import android.R;
import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Toast;
public class GPSActivity extends Activity
{
WebView position;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_item);
position = (WebView) findViewById(R.id.activity_main);
position.getSettings().setJavaScriptEnabled(true);
}
public void onLocationChanged(Location loc)
{
String Text ="My current location is: " + "Latitud="
+ loc.getLatitude() + "Longitud =" + loc.getLongitude();
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_LONG).show();
String url ="http://maps.google.com/staticmap?center="
+ loc.getLatitude() +loc.getLatitude()
+ "&zoom=14&size=512x512&maptype=mobile/&markers="
+ loc.getLatitude() + loc.getLongitude();
position.loadUrl(url);
}
}
the error is activity main cannot be resolved or is not a field, I think the id is in activity_main but correct me if I'm wrong, here it is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Webview
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Change it to
position = (WebView) findViewById(R.id.webview);
Also make sure you'e setting the correct layout
setContentView(R.layout.activity_main);
The reason is that the id of the WebView is not R.id.activity_main. In your case it is R.id.webview. The ID values are set in your XML layout via android:id="#+id/webview
Another possible issue. Remove import android.R; as well.
This is the reason it can't find your resources:
import android.R;
It expecting to find your R related stuff in the android.R that is precompiled. You need to remove that line and import your package's R not the precompiled R.
Solution
Remove the import android.R line.
Also ensure your project compiles and can generate the R.java during the build process.
position = (WebView) findViewById(R.id.webview); after you remove the import android.R.
It is looking for webview in android.R.id, but it is located in your_package_name.R.id.
Remove the
import android.R;
You will probabl still get errors that it is not recognized. This is because you are in a default package instead of your project package. You can get around it by importing your .R
So if you package name is com.GPS
then import com.GPS.R
View v=inflater.inflate(R.layout.fragment_two, container, false);
WebView mWebView = (WebView) v.findViewById(R.id.webView2);
I did that :)
I was able
I've been having the same issue with findViewByID(R.id.activity_main);, and I spent days trying out all the solutions I saw online.
I solved the problem using the following method:
I went to the XML document and gave my layout a name (ID): activity_main.
This line of code popped up in the TextView of my XML document: android:id="#+id/activity_main".
Immediately, I stopped having the activity_main problem.
Note: I also do not have the import.android.R statement.

Save button failing to upload data to Parse

I'm having trouble getting past the basics of having my app communicate with a server to store data.
I'm attempting to use Parse (https://parse.com/) as the backend of the Android app I'm working on. I got the basic "Quick Start" Parse app going fine, and was able to upload data from the app on my phone to my Parse account using the onCreate() method. Then I tried to create an app which would upload some data when a button is pressed. I can install and run the app, but when I press the button nothing seems to happen, and when I then check my Parse account no data has been uploaded. I included the Parse libs and added them to the build path.
Here is the app code-
package greg.mariani.saveLoad;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.parse.Parse;
import com.parse.ParseObject;
public class SaveLoad1Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
Parse.initialize(this, "private_app_token1", "private_app_token2");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void saveUpdates(View view) {
ParseObject updates = new ParseObject("Updates");
updates.put("court", "Brentwood Rec");
updates.put("update", "Game On");
updates.saveInBackground();
}
}
Here is the layout xml-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/save"
android:onClick="saveUpdates"/>
</LinearLayout>
Can anyone see what I'm doing wrong?
have you added internet permission to your manifest file?
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Android GPS map shows grid

After 30 hours of programming and failing at this, I realised I couldn't do what I wanted. So this is a last ditch effort to score a pass.
Trying to implement google api to show stuff on a map.
I've basically followed the Android tutorial entirely and it still refuses to work.
It just shows the grid on the MapView, my friend tested my api key so it should be fine.
The only permission I was supposed to use is
android.permission.INTERNET
I've seen the other thread, but I'm positive the key is fine and I think the permission is in the right place.
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="key"
/>
</LinearLayout>
manifest
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:debuggable="false">
<uses-library android:name="com.google.android.maps" />
<activity
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
public class Main extends MapActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable);
GeoPoint point = new GeoPoint(19240000,-99120000);
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
seems I was premature, I built another key, exactly as I did last time. This time the key worked.
but now the problem is, when I click on zoom, it force closes teh application
dont use debug.keystore. Use new keystore. Right click on ur project>Android tools> Export signed application package. Create new keystore (Remember alias name and password).
Now use following command in command prompt:
cd "C:\Program Files\Java\jdk1.7.0_01\bin
keytool -v -list -alias <ur alias name> -keystore <ur keystore name>.keystore -storepass android -keypass android
It asks for password later it gives a MD5 fingerprint Use that md5 fingerprint to generate google api key. Replace the key.
Now Project Right Click>Android tools>Export Signed Application package>
Use existing keystore
select previous keystore and u get apk in release mode. check installing this apk.It should run properly.
I think problem with your MyItemizedOverlay class only.
You mentioned when i click on zoom means zoom controls or on your android marker ??
I tested my code as you did but only the change is my own ItemizedOverlay class. its working fine for both zoom controls and marker click.
The only thing i can help you is, if your app crashed when you click marker on map, then you have to pass the Context to ItemizedOverlay class
If not, send your code i will try to solve your problem.

Categories

Resources