标签: android-maps

调用getSystemService(Context.LOCATION_SERVICE)并且未调用onLocationChanged时出现NullpointerException

我正在尝试创建一个更新当前gps位置的后台服务.我正在NullPointerException排队LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

HomeActivity推出了一项服务

startService(new Intent(getApplicationContext(), ForHire.class));
Run Code Online (Sandbox Code Playgroud)

Service(ForHire)创建TimerTask更新

public class ForHire extends Service {

...
private Timer getUpdatesNow = new Timer();
private Updates updates = new Updates(getUpdatesNow);

@Override
public void onCreate() {
    ...
    getUpdatesNow.schedule(updates, God.KM20TIME);
    Log.v("Taxeeta", "Notification created");
}

    private class Updates extends TimerTask implements LocationListener {
    private Timer getUpdatesNow;

    public Updates(Timer newGetUpdatesNow) {
        super();
        getUpdatesNow = newGetUpdatesNow;
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                God.KM20TIME, God.KM20DISTANCE, (LocationListener) this);
    }
    public void run() {
        ...
        //do …
Run Code Online (Sandbox Code Playgroud)

android android-maps android-location

5
推荐指数
1
解决办法
8719
查看次数

将谷歌地图显示为一个圆圈

我在我的一个活动的xml视图中使用了GoogleMapSupport片段.该片段目前位于我视角的150x150dip方块.我想知道是否有一种有效的方法来掩盖地图片段,使其显示为圆形而不是方形.我看了很多,发现这篇文章:Android屏蔽背景圆形渐变形状

但这似乎是一个使用画布的例子,我想实际掩盖的视图是一个MapSupportFragment ..下面是一个图像,显示了我想要实现的,如果可能的话和我当前的xml布局.

在此输入图像描述

<FrameLayout
    android:id="@+id/arFrame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >
</FrameLayout>

<TextView
    android:id="@+id/textViewLocation"
    android:layout_width="fill_parent"
    android:layout_height="20dp"
    android:text="no signal"
    android:textAppearance="?android:attr/textAppearanceSmall" />

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"

        android:layout_width="150dip"
        android:layout_height="150dip"
        android:layout_alignParentRight="true"
        class="com.google.android.gms.maps.SupportMapFragment" />

<com.KingNozzle.Views.KNMultiDirectionalSlidingDrawer
    xmlns:my="http://schemas.android.com/apk/res/com.KingNozzle"
    android:id="@+id/drawer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    my:content="@+id/content"
    my:direction="topToBottom"
    my:handle="@+id/handle" >

    <include
        android:id="@id/content"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        layout="@layout/empty_rel" />

    <ImageView
        android:id="@id/handle"
        android:layout_width="wrap_content"
        android:layout_height="40px"
        android:src="@drawable/sliding_drawer_handle_bottom" />
</com.KingNozzle.Views.KNMultiDirectionalSlidingDrawer>
Run Code Online (Sandbox Code Playgroud)

android android-maps android-fragments

5
推荐指数
0
解决办法
496
查看次数

Android GoogleMap或SupportMapFragment - 空指针异常

在我的应用程序中我在片段中显示谷歌地图版本2.但我得到Null指针异常

mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

这是我的完整代码:

    public class SearchResultMap extends Fragment{

    private GoogleMap mMap;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View fragmentView = inflater.inflate(R.layout.map, container, false);

        mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); // line no : 28

         mMap.addMarker(new MarkerOptions() .position(new LatLng(xxxxxx,xxxxxx)) .title("Current Location")
         .icon(BitmapDescriptorFactory.fromResource(R.drawable.ball_pointer))
         .snippet("xxxxx"));

        return fragmentView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

}
Run Code Online (Sandbox Code Playgroud)

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

   <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" /> …
Run Code Online (Sandbox Code Playgroud)

android android-maps google-play-services supportmapfragment android-maps-v2

5
推荐指数
2
解决办法
2万
查看次数

GPS定位启用后如何立即获取位置

我正在实现一个模块,需要用户的纬度经度来离线打卡考勤。

我已经按照LINK上的示例实现了GPSTracker类

但是启用 GPS 定位后,我正在打卡出勤,那么此类将返回空位置对象。但3060秒后它会正确返回位置对象。

我还在清单中添加了COARSE权限FINE,并获得了运行时权限。

所以我需要帮助如何在启用 GPS 定位后立即获取纬度和经度。

android android-maps android-location

5
推荐指数
1
解决办法
1711
查看次数

无法访问 androidx.savedstate.SavedStateRegistryOwner

我有以下课程。

public abstract class AbstractMapFragment extends SupportMapFragment implements OnMapReadyCallback
Run Code Online (Sandbox Code Playgroud)

不幸的是,但由于未知的原因,该类带有红色下划线,并且出现以下消息:Cannot access androidx.savedstate.SavedStateRegistryOwner

我该如何修复它?

java android android-maps

5
推荐指数
1
解决办法
2081
查看次数

Android:MapController.zoomToSpan:给出距离和中心点的跨度

我一直在Google和SO上研究这个问题,但是我被卡住了,我想我错过了一些基本的东西.我见过的大多数例子都没有处理任意mapWidth和单个点,只是Overlay的跨度.

我有一个地图点数据库,a MapView和a Geocoder.我可以在我的应用程序中搜索邮政编码,Address并由我的Geocoder.

使用这个Address,我可以构建一个GeoPoint并搜索我的数据库并获取附近点的列表.问题来自于尝试使用从返回Address点构造的跨度以及到数据库中最近点的距离来设置zoomToSpan .

我只希望跨度包含最近的两个点(如果可用).这是相关的代码:

Collections.sort(listingDisplay, mComparator);
    listingDisplayAdapter.notifyDataSetChanged();

    float spanWidth =0;

    if (listingDisplay.size() > 1) {

        spanWidth = (float) (2 * distanceFromPoint(listingDisplay.get(1),
                current));

    } else if (listingDisplay.size() == 1) {

        spanWidth = (float) (2 * distanceFromPoint(listingDisplay.get(0),
                current));

    }

    Log.v(TAG, "SpanWidth: " + spanWidth);

    // Create span
    int minLat = (int) (current.getLatitudeE6() - (spanWidth * 1E6) / 2);
    int maxLat = (int) (current.getLatitudeE6() + (spanWidth …
Run Code Online (Sandbox Code Playgroud)

android android-maps

4
推荐指数
1
解决办法
3084
查看次数

Google地图在地图中不显示任何内容

我正在活动中显示地图......但是当我在设备上运行应用程序时它没有显示任何内容,它只显示白屏并放大缩小选项... MAP键是正确的...谢谢..

AndroidManifest.xml中

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />



     <permission android:name="com.edxample.finalmap.permission.MAPS_RECEIVE"
         android:protectionLevel="signature" />
     <uses-permission android:name="com.edxample.finalmap.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature android:glEsVersion="0x00020000"
        android:required="true" />




    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.edxample.finalmap.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

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

    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

activity_main.xml中

<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" >

     <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:map="http://schemas.andoid.com/apk/es-auto" …
Run Code Online (Sandbox Code Playgroud)

android android-maps android-mapview

4
推荐指数
2
解决办法
7974
查看次数

选项卡中的Android Google地图v2重叠问题,标签中的多个地图

我是android新手,现在正在使用Google maps v2,我使用tabhost来显示Google map v2,在这个tabhost中我需要在不同的标签上显示两个Google maps v2.当我切换标签b/w两个包含地图的标签时,它会重叠.我不知道要克服这个问题.

//代码在这里用于两个选项卡

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
            .getMap();
    mMap.setMyLocationEnabled(true);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    //locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, this);
    Log.e("locamanager",""+locationManager);
    Criteria criteria=new Criteria(); // object to retrieve provider
    String provider = locationManager.getBestProvider(criteria, true);
    Location location=locationManager.getLastKnownLocation(provider);
    if(location!=null){
        onLocationChanged(location);
    }
    locationManager.requestLocationUpdates(provider, 400, 1000, this);


 }


@Override
public void onLocationChanged(Location location) {

    latLng = new LatLng(location.getLatitude(), location.getLongitude());
    Log.e("latlng",""+latLng);
    cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 15);
    mMap.animateCamera(cameraUpdate);
    locationManager.removeUpdates(this);

    new ReverseGeocodingTask(getBaseContext()).execute(latLng);

}
Run Code Online (Sandbox Code Playgroud)

有人有解决方案请帮帮我

感谢Advance

android android-maps google-maps-android-api-2 android-maps-v2

4
推荐指数
1
解决办法
3425
查看次数

public final void moveCamera(CameraUpdate update)和public final void animateCamera(CameraUpdate update)之间的区别?

这些方法有什么区别

public final void moveCamera(CameraUpdate update)和public final void animateCamera(CameraUpdate update)

GoogleMap类?

我什么时候应该调用getCameraPosition()?

android google-maps android-maps

4
推荐指数
1
解决办法
1638
查看次数

mMap.setOnMapClickListener中的空对象错误(this);

package com.example.mukesh.airpollution;




import android.graphics.Color;
import android.os.Bundle;
 import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
 import com.google.android.gms.maps.MapFragment;
 import com.google.android.gms.maps.OnMapReadyCallback;
 import com.google.android.gms.maps.model.CameraPosition;
 import com.google.android.gms.maps.model.LatLng;
 import com.google.android.gms.maps.model.LatLngBounds;
 import com.google.android.gms.maps.model.Polygon;
 import com.google.android.gms.maps.model.PolygonOptions;
 import com.google.maps.android.PolyUtil;
 import java.util.List;

 import java.util.ArrayList;

 public class MapsActivity extends FragmentActivity
    implements OnMapClickListener, OnMapReadyCallback {

//final int RQS_GooglePlayServices = 1;
private GoogleMap mMap;
//private GoogleMap googleMap;



boolean markerClicked;
PolygonOptions polygonOptions;
Polygon polygon;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is      ready …
Run Code Online (Sandbox Code Playgroud)

android google-maps android-maps android-maps-v2

4
推荐指数
1
解决办法
2679
查看次数