I’m trying to make application where user has an option to click on button “Find on Map”.
If user clicks “Find on Map” button, I would like to start new activity that contains google map.
I did this tutorial and map shows.
http://mobiforge.com/developing/story/using-google-maps-android
However this tutorial shows map in the main activity. That is why I made ViewMap activity which is exactly the same as the main activity in the tutorial showed above.
This is how I start ViewMap activity:
findOnMapButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// create an Intent to launch the ViewMap Activity
Intent viewMap = new Intent(ViewCourse.this, ViewMap.class);
startActivity(viewMap); // start the ViewContact Activity
}
});
Here is ViewMap.java:
package com.ijankovic.exammanager;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class ViewMap extends MapActivity {
private MapView mapView;
private MapController mc;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_map);
mapView = (MapView) findViewById(R.id.mapview);
mc = mapView.getController();
String coordinates[] = {"31.567615", "74.360962"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
GeoPoint p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(7);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
return false; // we are not displaying route information
}
}
Here is view_map.xml:
<?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" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0jHJ3aWhSfOMZ1gjFMGc8xTf7mASBEtQcynZPOQ"
android:clickable="true"
android:enabled="true" />
</RelativeLayout>
I know my API key works for sure since map displays if I put ViewMap as the main activity.
However if I try to put it in activity that gets called on button clicked, map opens but everything is grey and tiles do not load. There is Google logo in the bottom left corner.
Here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ijankovic.exammanager"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<uses-permission android:name="android.premission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<activity
android:name="com.ijankovic.exammanager.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ViewCourse"
android:label="@string/app_name"></activity>
<activity android:name=".ViewMap"
android:label="@string/app_name"></activity>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
Problem:
Is something wrong with my Intent and ViewMap activity call?
Any suggestions are welcome. Thanks in advance!
Edit:
I managed to get google maps with this call:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=New+York+NY));
startActivity(i);
However this seems to start google maps app. It is not google maps within my app like the tutorial showed.
I figured out what the problem was!
What I had:
What it should be:
So I typed premission instead of permission.
I’m surprised that eclipse does not point syntax errors in AndroidManifest.xml file.