gpt4 book ai didi

java - 添加 Geojson 时 getMap() 和 addLayerToMap() 错误

转载 作者:行者123 更新时间:2023-12-02 10:07:17 24 4
gpt4 key购买 nike

我正在尝试添加 GeoJson 文件。我使用google https://developers.google.com/maps/documentation/android-sdk/utility/geojson的代码示例但我收到以下错误。

getMap()

Cannot resolve method 'getMap()'

addLayerToMap()

Cannot resolve symbol 'addLayerToMap'

我读到我必须使用 getmapAsync 更改 getmap,但它没有改变任何内容。

package com.example.testnavbar;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;
import com.google.maps.android.data.geojson.GeoJsonFeature;
import com.google.maps.android.data.geojson.GeoJsonLayer;
import com.google.maps.android.data.geojson.GeoJsonLineString;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.List;

import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;


public class HomeFragment extends Fragment implements OnMapReadyCallback {

private final static String mLogTag = "GeoJson";

GoogleMap mGoogleMap;
MapView mMapView;
View mView;


@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mView = inflater.inflate( R.layout.fragment_home, container, false );
return mView;
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated( view, savedInstanceState );

mMapView = (MapView) mView.findViewById( R.id.map );
if (mMapView != null){
mMapView.onCreate( null );
mMapView.onResume();
mMapView.getMapAsync( this );
}
}


GeoJsonLayer layer = new GeoJsonLayer(getMap(), R.raw.picnicsites,
getApplicationContext());

layer.addLayerToMap();


@Override
public void onMapReady(GoogleMap googleMap) {
MapsInitializer.initialize(getContext());

mGoogleMap = googleMap;

googleMap.setMapType( GoogleMap.MAP_TYPE_SATELLITE );

googleMap.addMarker( new MarkerOptions()
.position(new LatLng( 35.126411, 33.429859 ) )
.title( "Cyprus" )
.snippet( "Center of island" )
.icon( BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

CameraPosition Liberty = CameraPosition.builder()
.target(new LatLng( 36.126411, 33.429859 ))
.zoom( 8f )
.bearing( 0 )
.tilt( 0 )
.build();

googleMap.moveCamera( CameraUpdateFactory.newCameraPosition( Liberty ) );

}
}

最佳答案

似乎是这样的语句:

GeoJsonLayer layer = new GeoJsonLayer(getMap(), R.raw.picnicsites,
getApplicationContext());

layer.addLayerToMap();

是错误的 - 它们应该位于 onMapReady(GoogleMap googleMap) 内(并且新的 GeoJsonLayer(getMap()... 应该更改为 GeoJsonLayer(mGoogleMap ...)像这样:

@Override
public void onMapReady(GoogleMap googleMap) {
MapsInitializer.initialize(getContext());

mGoogleMap = googleMap;

// move them here:
GeoJsonLayer layer = new GeoJsonLayer(mGoogleMap, R.raw.picnicsites,
getApplicationContext());

layer.addLayerToMap();

googleMap.setMapType( GoogleMap.MAP_TYPE_SATELLITE );

googleMap.addMarker( new MarkerOptions()
.position(new LatLng( 35.126411, 33.429859 ) )
.title( "Cyprus" )
.snippet( "Center of island" )
.icon( BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

CameraPosition Liberty = CameraPosition.builder()
.target(new LatLng( 36.126411, 33.429859 ))
.zoom( 8f )
.bearing( 0 )
.tilt( 0 )
.build();

googleMap.moveCamera( CameraUpdateFactory.newCameraPosition( Liberty ) );

}

并删除

import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;

线。

关于java - 添加 Geojson 时 getMap() 和 addLayerToMap() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55260134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com