gpt4 book ai didi

android - LatLng 的标记未显示

转载 作者:行者123 更新时间:2023-11-30 02:58:24 26 4
gpt4 key购买 nike

在我更改包名称之前,一切都在我的设备上正常工作...一旦更改 pkg,相机就不会移动到初始 latlng。此外,标记不会显示。

package com.vaishnavismeclass.divyadesammap.english;

import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;



import android.app.Activity;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity implements OnMarkerClickListener {


private GoogleMap mMap;

/*
* declaration of all the parameters
* to display paasurams
* on a list
* this will act as query critiera
*/
public final static String EXTRA_CATEGORY = "com.vaishnavismeclass.divyadesamsmap.englis.CATEGORY";
public final static String EXTRA_START = "com.vaishnavismeclass.divyadesamsmap.englis.START";
public final static String EXTRA_ENDING = "com.vaishnavismeclass.divyadesamsmap.englis.ENDING";
public final static String EXTRA_PASURAMNUMBER = "com.vaishnavismeclass.divyadesamsmap.englis.PASURAMNUMBER";
public final static String EXTRA_AAYIRAM = "com.vaishnavismeclass.divyadesamsmap.englis.AAYIRAM";
public final static String EXTRA_AZHWAAR = "com.vaishnavismeclass.divyadesamsmap.englis.AZHWAAR";
public final static String EXTRA_MANGALASASANAMON = "com.vaishnavismeclass.divyadesamsmap.englis.MANGALASASANAMON";
public final static String EXTRA_SUBCATEGORY = "com.vaishnavismeclass.divyadesamsmap.englis.SUBCATEGORY";
public final static String EXTRA_TITLE = "com.vaishnavismeclass.divyadesamsmap.englis.TITLE";

/*
*
* Define latlng
* of all the divyadesams
* with a variable
*/
static final LatLng lTiruSalagramam= new LatLng(28.816885 , 83.870814);



/*
*
* Define divyadesam string
* for passing to the database
* to query
*/
static final String mTiruSalagramam = "Tiru Salagramam";


/*
* Define markers
* as divyadesams without ( - and space
*
*/
Marker TiruSalagramam;

@Override
public boolean onMarkerClick(Marker marker) {
Intent intent = new Intent(getApplicationContext(),
Paasurams.class);
/*
* Create intent data
* and pass to respective
* pages
*/
Log.d("VC","Marker selected is "+marker.toString());
if (marker.equals(TiruSalagramam)){intent.putExtra(EXTRA_MANGALASASANAMON,mTiruSalagramam );}


startActivity(intent);
return false;
}

/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Sets the map type to be "hybrid"
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
/*
*
* Setup my location
*
*
*/
if (mMap == null)
return; // Google Maps not available
try {
MapsInitializer.initialize(this);
}
catch (GooglePlayServicesNotAvailableException e) {
Log.e("VC", "Have GoogleMap but then error", e);
return;
}
mMap.setMyLocationEnabled(true);
// Getting LocationManager object from System Service LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();

// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);

// Getting Current Location
Location location = locationManager.getLastKnownLocation(provider);

if(location!=null){
// Getting latitude of the current location
double latitude = location.getLatitude();

// Getting longitude of the current location
double longitude = location.getLongitude();

// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);

LatLng myPosition = new LatLng(latitude, longitude);

mMap.addMarker(new MarkerOptions().position(myPosition).title("Current Location"));

/*
* Show the location name
* on the marker always
*
*/
//TiruSalagramam.showInfoWindow();
/*
* Do basic setup if required
*/
setUpMapIfNeeded();

//
GoogleMapOptions options = new GoogleMapOptions();
options.mapType(GoogleMap.MAP_TYPE_SATELLITE)
.compassEnabled(true)
.rotateGesturesEnabled(true)
.tiltGesturesEnabled(true);
/*
* Focus camera to Nagpur
*/
CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(21.153889,
79.083056));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(4);

mMap.moveCamera(center);
mMap.animateCamera(zoom);

/*
* customize the marker color
*/

TiruSalagramam= mMap.addMarker(new MarkerOptions().position(lTiruSalagramam).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)).title(mTiruSalagramam));

mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

@Override
public void onInfoWindowClick(Marker marker) {
// TODO Auto-generated method stub
Intent intent = new Intent(getApplicationContext(),
Paasurams.class);
if (marker.equals(TiruSalagramam)){intent.putExtra(EXTRA_MANGALASASANAMON,mTiruSalagramam );}

startActivity(intent);


}

}
);
}

}

private void setUpMapIfNeeded() {
// TODO Auto-generated method stub
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
// The Map is verified. It is now safe to manipulate the map.

}
}
}
}

我已经删除了大多数其他标记和相关代码以适应大小。

list 是

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vaishnavismeclass.divyadesammap.english"
android:versionCode="2"
android:versionName="2.2" >

<permission
android:name="com.vaishnavismeclass.divyadesammap.english.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />

<uses-permission android:name="com.vaishnavismeclass.divyadesammap.english.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" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.vaishnavismeclass.divyadesammap.english.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>
<activity
android:name="com.vaishnavismeclass.divyadesammap.english.Paasurams"
android:label="Paasurams"
android:parentActivityName="com.vaishnavismeclass.divyadesammap.english.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.vaishnavismeclass.divyadesammap.english.MainActivity" />
</activity>

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBWA65v6k62oLOD_20SiGYAo0x01F3OzAU" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>

</manifest>

最佳答案

试试这个 link

这个link

可能会有帮助..

Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using. Clean all projects afterwards and see what happens.

关于android - LatLng 的标记未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22928370/

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