问题描述
我一直在使用有关谷歌地图API和谷歌Places API的这个下面的教程。
的
这是非常不错的。我已成功地在地图上显示附近的地方标记,并显示不同类型不同类别标记为好。不过,我也想,当用户点击我的标志之一在警报对话框,显示建立的电话号码。对于这一点,我使用的是地方详细搜索。
下面,我将提供我有问题我地图活动code片段。
//地图活动的OnCreate()
//检查是否为空nearPlaces
如果(nearPlaces.results!= NULL)
{
//循环遍历所有的地方
对于(地点地点:nearPlaces.results)
{ 纬度= place.geometry.location.lat;
经度= place.geometry.location.lng;
placeRef = place.reference; 新LoadDetails()执行(placeRef)。 对于(一个String:place.types)
{
如果(s.contains(餐厅))
{
。可绘制rMarker = this.getResources()getDrawable(R.drawable.restaurant); //phone=lp.getPhone();
iOverlay =新MyItemizedOverlay(rMarker,这一点); // GeoPoint对象放置在地图上
GP =新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); //地图覆盖项目
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating ++电话); iOverlay.addOVerlay(OITEM); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay);
}
我有我想建立的电话号码一个变量字符串电话。
下面是一个扩展的AsyncTask的LoadDetails类
私有类LoadDetails扩展的AsyncTask<字符串,字符串,字符串>
{
@覆盖
保护无效onPostExecute(字符串结果){
如果(placeDetails!= NULL)
{
如果(placeDetails.status.equals(OK))
{
如果(placeDetails.result!= NULL)
{
手机= placeDetails.result.formatted_phone_number;
Log.d(固定电话的,电话);
}
}
} } @覆盖
保护字符串doInBackground(字符串... PARAMS){ String引用=参数[0];
googlePlaces =新GooglePlaces(); 尝试{
placeDetails = googlePlaces.getPlaceDetails(参考);
}赶上(例外五){
e.printStackTrace();
}
返回null;
}
}
在OnPostExecute,变量的手机设置,我的LogCat中显示了各个地方的电话号码。然而,当我去我的手机在我的地图的活动,并单击餐厅的标志,可变手机总是空。我该如何解决这个问题?
任何帮助将是巨大的。
先谢谢了。
编辑:整个MapActivity
公共类地图扩展MapActivity {
MapView类MapView类;
MapController MC;
GP的GeoPoint,FGP;
清单<&叠加GT; mapOverlays;
OverlayItem OITEM;
MyItemizedOverlay iOverlay;串placeRef,电话,placePhone;
双纬度,经度;
双user_lat,user_long;
双friendLat,friendLong;
用户名字符串,FRIENDNAME,userStatus,userPhoneNumber;//最近的地方
PlacesList nearPlaces;GooglePlaces googlePlaces;PlaceDetails placeDetails;@覆盖
保护无效的onCreate(捆绑为arg0){
// TODO自动生成方法存根
super.onCreate(为arg0);
的setContentView(R.layout.map);
图形页面=(图形页面)findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(真); MC = mapView.getController(); 意向I = getIntent(); 如果(我!= NULL)
{
//接收用户的纬度和长
user_lat = i.getDoubleExtra(userLAT,0);
user_long = i.getDoubleExtra(userLONG,0); userPhoneNumber = i.getStringExtra(userNUMBER); //获取用户的状态,他们发布
userStatus = i.getStringExtra(STATUS);
//获取用户名
的userName = i.getStringExtra(username的); //接收朋友的纬度和长 friendLat = i.getDoubleExtra(friendLAT,0);
friendLong = i.getDoubleExtra(friendLong,0);
//获取nearPlaces列表从主要活动
nearPlaces =(PlacesList)i.getSerializableExtra(userNearPlaces);
FRIENDNAME = i.getStringExtra(FRIENDNAME);
Log.d(地图,用户名++ user_lat ++ user_long);
Log.d(地图2,FRIENDNAME ++ friendLat ++ friendLat);
GP =新的GeoPoint((INT)(user_lat * 1E6),(INT)(user_long * 1E6)); //朋友的的GeoPoint
FGP =新的GeoPoint((INT)(friendLat * 1E6),(INT)(friendLong * 1E6)); } mapOverlays =调用MapView.getOverlays();
可绘制标记= this.getResources()getDrawable(R.drawable.you)。
iOverlay =新MyItemizedOverlay(标记,这一点);
OITEM =新OverlayItem(GP,您现在的位置,+用户名,userStatus); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay);
。可绘制fMarker = this.getResources()getDrawable(R.drawable.smiley); iOverlay =新MyItemizedOverlay(fMarker,这一点); //朋友标记添加到地图
OITEM =新OverlayItem(FGP,FRIENDNAME +的位置,这是你的朋友);
iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay); //检查是否为空nearPlaces
如果(nearPlaces.results!= NULL)
{
//循环遍历所有的地方
对于(地点地点:nearPlaces.results)
{ 纬度= place.geometry.location.lat;
经度= place.geometry.location.lng;
placeRef = place.reference;
placePhone = place.phone; 新LoadDetails()执行(placeRef)。 对于(一个String:place.types)
{
如果(s.contains(餐厅))
{
。可绘制rMarker = this.getResources()getDrawable(R.drawable.restaurant); //phone=lp.getPhone();
iOverlay =新MyItemizedOverlay(rMarker,这一点); // GeoPoint对象放置在地图上
GP =新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); //地图覆盖项目
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating ++ placePhone); iOverlay.addOVerlay(OITEM); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay);
} 如果((s.contains(咖啡))|| place.name.contains(咖啡))
{
。可绘制cafeMarker = this.getResources()getDrawable(R.drawable.cafe); iOverlay =新MyItemizedOverlay(cafeMarker,这一点);
// GeoPoint对象放置在地图上
GP =新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); //地图覆盖项目
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating); iOverlay.addOVerlay(OITEM); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay); } 否则如果((s.contains(liquor_store))|| place.name.contains(酒类))
{
可绘制barMarker = this.getResources()getDrawable(R.drawable.bar)。 iOverlay =新MyItemizedOverlay(barMarker,这一点);
// GeoPoint对象放置在地图上
GP =新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); //地图覆盖项目
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating); iOverlay.addOVerlay(OITEM); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay); } 否则如果(s.contains(department_store)|| s.contains(clothing_store)|| s.contains(convenience_store))
{
可绘制shopMarker = this.getResources()getDrawable(R.drawable.mall)。 iOverlay =新MyItemizedOverlay(shopMarker,这一点);
// GeoPoint对象放置在地图上
GP =新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); //地图覆盖项目
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating); iOverlay.addOVerlay(OITEM); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay); } 否则,如果(s.contains(医院))
{
。可绘制hMarker = this.getResources()getDrawable(R.drawable.hospital); iOverlay =新MyItemizedOverlay(hMarker,这一点);
// GeoPoint对象放置在地图上
GP =新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); //地图覆盖项目
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating); iOverlay.addOVerlay(OITEM); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay); } 否则如果(s.contains(movie_theater))
{
。可绘制movieMarker = this.getResources()getDrawable(R.drawable.movierental); iOverlay =新MyItemizedOverlay(movieMarker,这一点);
// GeoPoint对象放置在地图上
GP =新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); //地图覆盖项目
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating); iOverlay.addOVerlay(OITEM); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay); } 否则,如果(s.contains(药房))
{
。可绘制pMarker = this.getResources()getDrawable(R.drawable.pharmacy); iOverlay =新MyItemizedOverlay(pMarker,这一点);
// GeoPoint对象放置在地图上
GP =新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); //地图覆盖项目
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating); iOverlay.addOVerlay(OITEM); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay); }
否则如果(s.contains(hair_care))
{
可绘制bMarker = this.getResources()getDrawable(R.drawable.barber)。 iOverlay =新MyItemizedOverlay(bMarker,这一点);
// GeoPoint对象放置在地图上
GP =新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); //地图覆盖项目
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating); iOverlay.addOVerlay(OITEM); iOverlay.addOVerlay(OITEM);
mapOverlays.add(iOverlay); } }
}
} mapView.getController(); mc.animateTo(GP);
mc.setZoom(15);
mc.setCenter(GP); mapView.invalidate();
}@覆盖
保护布尔isRouteDisplayed(){
// TODO自动生成方法存根
返回false;
}私有类LoadDetails扩展的AsyncTask<字符串,字符串,字符串>
{
@覆盖
保护无效onPostExecute(字符串结果){
placePhone =结果; //我的LogCat中显示的电话号码被分配到placePhone
Log.d(placePhone,placePhone); } @覆盖
保护字符串doInBackground(字符串... PARAMS){ String引用=参数[0];
googlePlaces =新GooglePlaces(); 尝试{
placeDetails = googlePlaces.getPlaceDetails(参考);
}赶上(例外五){
e.printStackTrace();
}
如果(placeDetails!= NULL)
{
如果(placeDetails.status.equals(OK))
{
如果(placeDetails.result!= NULL)
{
手机= placeDetails.result.formatted_phone_number; }
}
}
回电话;
}
}私有类MyItemizedOverlay扩展ItemizedOverlay< OverlayItem>
{
私人的ArrayList< OverlayItem> mOverlays =新的ArrayList< OverlayItem>();
上下文mContext; 公共MyItemizedOverlay(可绘制标记){
超(boundCenterBottom(标记));
} 公共MyItemizedOverlay(可绘制标记,上下文的背景下){
超(boundCenterBottom(标记));
mContext =背景;
} @覆盖
保护OverlayItem createItem中(int i)以{
返回mOverlays.get(ⅰ);
} @覆盖
公众诠释大小(){
返回mOverlays.size();
} 公共无效addOVerlay(OverlayItem叠加)
{
mOverlays.add(覆盖);
填充();
}
@覆盖
公共布尔中的onTap(int i)以{ OverlayItem项= mOverlays.get(ⅰ);
AlertDialog.Builder对话框=新AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
如果(item.getTitle()。包含(位置))
{
dialog.setNegativeButton(发送短信,新OnClickListener(){ 公共无效的onClick(DialogInterface对话,诠释它){
意图smsIntent =新意图(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setType(vnd.android-DIR / MMS短信);
smsIntent.setData(Uri.parse(短信:+ userPhoneNumber));
startActivity(smsIntent); }
}); dialog.setPositiveButton(呼叫,新OnClickListener(){ 公共无效的onClick(DialogInterface对话,诠释它){
字符串URI =电话:+ userPhoneNumber.trim();
意图callIntent =新意图(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(URI));
startActivity(callIntent); }
});
}
dialog.show(); 返回true;
}
}
}
OITEM =新OverlayItem(GP,place.name,place.vicinity +\\ n+评级:+ place.rating ++ place.formatted_phone_number);
试试这个place.formatted_phone_number
I have been using this following tutorial regarding the Google Maps API and Google Places API.
http://www.androidhive.info/2012/08/android-working-with-google-places-and-maps-tutorial/
It is very good. I have managed to display markers of nearby places on a map, and display different types of markers for different categories as well. However, I would also like to display the establishment's phone number in an alert dialog when the user clicks on one of my markers. For this, I am using a Place Detail search.
Below, I will provide a snippet of my Map Activity code that I am having problems with.
//Map Activity OnCreate()
//Check for null nearPlaces
if(nearPlaces.results!=null)
{
//Loop through all places
for(Place place:nearPlaces.results)
{
latitude=place.geometry.location.lat;
longitude=place.geometry.location.lng;
placeRef=place.reference;
new LoadDetails().execute(placeRef);
for(String s:place.types)
{
if(s.contains("restaurant"))
{
Drawable rMarker=this.getResources().getDrawable(R.drawable.restaurant);
//phone=lp.getPhone();
iOverlay=new MyItemizedOverlay(rMarker,this);
//GeoPoint to place on map
gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
//Map overlay item
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating+" "+phone);
iOverlay.addOVerlay(oItem);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
}
I have a variable String phone which I want to be the establishment's phone number.
Here is the LoadDetails class which extends AsyncTask
private class LoadDetails extends AsyncTask<String, String, String>
{
@Override
protected void onPostExecute(String result) {
if(placeDetails!=null)
{
if(placeDetails.status.equals("OK"))
{
if(placeDetails.result!=null)
{
phone=placeDetails.result.formatted_phone_number;
Log.d("Phone #'s",phone);
}
}
}
}
@Override
protected String doInBackground(String... params) {
String reference=params[0];
googlePlaces=new GooglePlaces();
try{
placeDetails=googlePlaces.getPlaceDetails(reference);
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}
In OnPostExecute, variable phone is set and my LogCat shows the phone numbers of various places. However, when I go to my Map Activity on my phone, and click a marker of a restaurant, the variable phone is always null. How do I fix this?
Any help would be great.
Thanks in advance.
EDIT: Entire MapActivity
public class Map extends MapActivity{
MapView mapView;
MapController mc;
GeoPoint gp, fGP;
List<Overlay> mapOverlays;
OverlayItem oItem;
MyItemizedOverlay iOverlay;
String placeRef,phone,placePhone;
double latitude,longitude;
double user_lat,user_long;
double friendLat,friendLong;
String userName,friendName,userStatus,userPhoneNumber;
//Nearest Places
PlacesList nearPlaces;
GooglePlaces googlePlaces;
PlaceDetails placeDetails;
@Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.map);
mapView=(MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mc=mapView.getController();
Intent i=getIntent();
if (i!=null)
{
//Receive User's Lat and Long
user_lat=i.getDoubleExtra("userLAT", 0);
user_long=i.getDoubleExtra("userLONG",0);
userPhoneNumber=i.getStringExtra("userNUMBER");
//Get User's Status they posted
userStatus=i.getStringExtra("STATUS");
//Get User's Name
userName=i.getStringExtra("userNAME");
//Receive Friend's Lat and Long
friendLat=i.getDoubleExtra("friendLAT", 0);
friendLong=i.getDoubleExtra("friendLong",0);
//Obtain nearPlaces List from Main Activity
nearPlaces=(PlacesList) i.getSerializableExtra("userNearPlaces");
friendName=i.getStringExtra("friendNAME");
Log.d("Map", userName+ " " +user_lat + " " + user_long);
Log.d("Map2", friendName+ " " + friendLat + " " + friendLat);
gp=new GeoPoint((int)(user_lat*1E6),(int)(user_long*1E6));
//Friend's GeoPoint
fGP=new GeoPoint((int)(friendLat*1E6),(int)(friendLong*1E6));
}
mapOverlays=mapView.getOverlays();
Drawable marker=this.getResources().getDrawable(R.drawable.you);
iOverlay=new MyItemizedOverlay(marker, this);
oItem=new OverlayItem(gp,"Your Location, "+userName,userStatus);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
Drawable fMarker=this.getResources().getDrawable(R.drawable.smiley);
iOverlay=new MyItemizedOverlay(fMarker,this);
//Add friend marker to the map
oItem=new OverlayItem(fGP,friendName+"'s Location", "This is your friend");
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
//Check for null nearPlaces
if(nearPlaces.results!=null)
{
//Loop through all places
for(Place place:nearPlaces.results)
{
latitude=place.geometry.location.lat;
longitude=place.geometry.location.lng;
placeRef=place.reference;
placePhone=place.phone;
new LoadDetails().execute(placeRef);
for(String s:place.types)
{
if(s.contains("restaurant"))
{
Drawable rMarker=this.getResources().getDrawable(R.drawable.restaurant);
//phone=lp.getPhone();
iOverlay=new MyItemizedOverlay(rMarker,this);
//GeoPoint to place on map
gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
//Map overlay item
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating+" "+placePhone);
iOverlay.addOVerlay(oItem);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
}
if((s.contains("cafe"))||place.name.contains("cafe"))
{
Drawable cafeMarker=this.getResources().getDrawable(R.drawable.cafe);
iOverlay=new MyItemizedOverlay(cafeMarker,this);
//GeoPoint to place on map
gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
//Map overlay item
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);
iOverlay.addOVerlay(oItem);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
}
else if((s.contains("liquor_store"))||place.name.contains("liquors"))
{
Drawable barMarker=this.getResources().getDrawable(R.drawable.bar);
iOverlay=new MyItemizedOverlay(barMarker,this);
//GeoPoint to place on map
gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
//Map overlay item
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);
iOverlay.addOVerlay(oItem);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
}
else if(s.contains("department_store")||s.contains("clothing_store")||s.contains("convenience_store"))
{
Drawable shopMarker=this.getResources().getDrawable(R.drawable.mall);
iOverlay=new MyItemizedOverlay(shopMarker,this);
//GeoPoint to place on map
gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
//Map overlay item
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);
iOverlay.addOVerlay(oItem);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
}
else if(s.contains("hospital"))
{
Drawable hMarker=this.getResources().getDrawable(R.drawable.hospital);
iOverlay=new MyItemizedOverlay(hMarker,this);
//GeoPoint to place on map
gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
//Map overlay item
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);
iOverlay.addOVerlay(oItem);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
}
else if(s.contains("movie_theater"))
{
Drawable movieMarker=this.getResources().getDrawable(R.drawable.movierental);
iOverlay=new MyItemizedOverlay(movieMarker,this);
//GeoPoint to place on map
gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
//Map overlay item
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);
iOverlay.addOVerlay(oItem);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
}
else if(s.contains("pharmacy"))
{
Drawable pMarker=this.getResources().getDrawable(R.drawable.pharmacy);
iOverlay=new MyItemizedOverlay(pMarker,this);
//GeoPoint to place on map
gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
//Map overlay item
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);
iOverlay.addOVerlay(oItem);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
}
else if(s.contains("hair_care"))
{
Drawable bMarker=this.getResources().getDrawable(R.drawable.barber);
iOverlay=new MyItemizedOverlay(bMarker,this);
//GeoPoint to place on map
gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
//Map overlay item
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);
iOverlay.addOVerlay(oItem);
iOverlay.addOVerlay(oItem);
mapOverlays.add(iOverlay);
}
}
}
}
mapView.getController();
mc.animateTo(gp);
mc.setZoom(15);
mc.setCenter(gp);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
private class LoadDetails extends AsyncTask<String, String, String>
{
@Override
protected void onPostExecute(String result) {
placePhone=result;
//My Logcat shows phone numbers being assigned to placePhone
Log.d("placePhone",placePhone);
}
@Override
protected String doInBackground(String... params) {
String reference=params[0];
googlePlaces=new GooglePlaces();
try{
placeDetails=googlePlaces.getPlaceDetails(reference);
}catch (Exception e){
e.printStackTrace();
}
if(placeDetails!=null)
{
if(placeDetails.status.equals("OK"))
{
if(placeDetails.result!=null)
{
phone=placeDetails.result.formatted_phone_number;
}
}
}
return phone;
}
}
private class MyItemizedOverlay extends ItemizedOverlay<OverlayItem>
{
private ArrayList<OverlayItem> mOverlays=new ArrayList<OverlayItem>();
Context mContext;
public MyItemizedOverlay(Drawable marker) {
super(boundCenterBottom(marker));
}
public MyItemizedOverlay(Drawable marker,Context context) {
super(boundCenterBottom(marker));
mContext=context;
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
public void addOVerlay(OverlayItem overlay)
{
mOverlays.add(overlay);
populate();
}
@Override
public boolean onTap(int i) {
OverlayItem item= mOverlays.get(i);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
if(item.getTitle().contains("Location"))
{
dialog.setNegativeButton("Send SMS", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent smsIntent=new Intent(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.setData(Uri.parse("sms:"+userPhoneNumber));
startActivity(smsIntent);
}
});
dialog.setPositiveButton("Call", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String uri="tel:"+userPhoneNumber.trim();
Intent callIntent=new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(uri));
startActivity(callIntent);
}
});
}
dialog.show();
return true;
}
}
}
oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating+" "+ place.formatted_phone_number);
try this place.formatted_phone_number
这篇关于显示格式的电话号码,从谷歌的地方API在Android上的一个警告对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!