2012-02-22 18 views
1

我正在考慮爲Android創建可顯示Google地圖的Widget。 雖然我做了兩個類繼承與MapActivity和另一個與AppWidgetProvider,但我不知道如何使用它們。任何人都可以幫忙嗎?如何在android中創建Widget中的Google地圖

package com.leaning.widget; 

import android.app.PendingIntent; 
import android.appwidget.AppWidgetManager; 
import android.appwidget.AppWidgetProvider; 
import android.content.Context; 
import android.content.Intent; 
import android.net.Uri; 
import android.widget.RemoteViews; 

public class MapWidgo extends AppWidgetProvider { 

MapGoogle obj = new MapGoogle(); 

@Override 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
    int[] appWidgetIds) { 
// TODO Auto-generated method stub 
super.onUpdate(context, appWidgetManager, appWidgetIds); 

for(int i=0;i<appWidgetIds.length;i++) 
{ 
    int appWidgetId = appWidgetIds[i]; 

    Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://maps.google.com")); 
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); 

    RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.main); 
    remote.setOnClickPendingIntent(R.id.webView1, pendingIntent); 

    appWidgetManager.updateAppWidget(appWidgetId, remote); 

} 
} 
}  

現在下面是我MapGoogle類

package com.leaning.widget; 

import android.content.Context; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
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 MapGoogle extends MapActivity { 
@Override 
protected void onCreate(Bundle icicle) { 
    // TODO Auto-generated method stub 
    super.onCreate(icicle); 

    MapView mapview = (MapView) findViewById(R.id.mySecretMap); 
    mapview.setBuiltInZoomControls(true); 

    final MapController controller = mapview.getController(); 

    LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

    LocationListener listener = new LocationListener() { 

     public void onStatusChanged(String provider, int status, Bundle extras) { 
      // TODO Auto-generated method stub 

     } 

     public void onProviderEnabled(String provider) { 
      // TODO Auto-generated method stub 

     } 

     public void onProviderDisabled(String provider) { 
      // TODO Auto-generated method stub 

     } 

     public void onLocationChanged(Location location) { 
      // TODO Auto-generated method stub 
      controller.setCenter(new GeoPoint((int)location.getLongitude(),(int)location.getLatitude())); 
     } 
    }; 

    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, listener); 
} 

@Override 
protected boolean isRouteDisplayed() { 
    // TODO Auto-generated method stub 
    return false; 
} 
} 

,最後一個是我的清單文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.leaning.widget" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk android:minSdkVersion="10" /> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

<application 

    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <uses-library android:name="com.google.android.maps" /> 

    <receiver android:name=".MapWidgo"> 

     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

     <meta-data android:name="android.appwidget.provider"  android:resource="@xml/widgetresource"/> 
    </receiver> 

    <activity android:name=".MapGoogle"> 

    </activity> 

</application> 

我希望有一個快速的解決方案!

+0

你有沒有成功與此?我想在我的主屏幕上放置一個'迷你Google地圖'小部件! – 2013-05-15 01:29:42

+0

我做了我的研究,但沒有得到答案,然後我離開了它。如果您獲得任何成功,請分享您的答案。 – iConfused 2013-06-17 16:47:12

回答

0

也許你可以有一個Web服務,它讀取谷歌地圖網址,並將其轉換爲圖像。 你需要的僅僅是一個能夠顯示來自網址的圖像的小部件(在Play上有很多)

相關問題