Marv
Marv

Reputation: 33

google maps isn't showing

In my app, I will use Google navigation when I open a Google link

This is my code:

public class FullscreenActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fullscreen);

    webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new myWebClient());
    webView.loadUrl("http://www.mywebsite.nl/");
    webView.setVerticalScrollBarEnabled(false);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
}



public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    // TODO Auto-generated method stub
    super.onPageStarted(view, url, favicon);
}

@Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) {

 if (url.startsWith("tel:")) { 
         Intent intent = new Intent(Intent.ACTION_DIAL,
                 Uri.parse(url)); 
         startActivity(intent); 
 }else if(url.startsWith("http:") || url.startsWith("https:")) {
     view.loadUrl(url);
 }
 return true;

    }
}

    public static void maps(Activity activity, String address) {

   try {

    Intent intent = new Intent(Intent.ACTION_VIEW,         Uri.parse("http://maps.google.com/maps?q=" + address));
    activity.startActivity(intent);

} catch (ActivityNotFoundException e) {
    Toast.makeText(activity, activity.getString(R.id.webView), Toast.LENGTH_SHORT).show();
}

public static void navigation(Activity activity, String address) {

try {

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + address));
    activity.startActivity(intent);

} catch (ActivityNotFoundException e) {

    Toast.makeText(activity, activity.getString(R.id.webView), Toast.LENGTH_SHORT).show();
}
 }

public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
        webView.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
   }

Is there something I forgot? When I click on a google.navigation?q=rotterdam it does nothing. I'll hope anyone can help me.

Upvotes: 0

Views: 221

Answers (1)

Viswanath Lekshmanan
Viswanath Lekshmanan

Reputation: 10083

You should add the key in the manifest:

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="xxxxxxxxxxxxxxxxxxxx"/>

and also add permissions

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

For more https://developers.google.com/maps/documentation/android/start

Upvotes: 1

Related Questions