谷歌地图V2 - 设置我的两个位置,并放大 [英] Google Maps v2 - set both my location and zoom in

查看:117
本文介绍了谷歌地图V2 - 设置我的两个位置,并放大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,没有人知道如何设置谷歌地图后,打开我的两个位置,并在一个放大的看法?

目前,主视图中打开了非洲,一路缩小。

所以,我一直在寻找几天了,所有我能看到的是:

1)你不能动画两件事情(如放大,去我的位置)在一个谷歌地图?所以,如果我能想出​​如何设置缩放之前,我设置了动画,那么这个问题就迎刃而解了。倾向于往往是问题,你可以换一个,而不是两个。

2)我发现其他类可能是有用的,但对如何建立code这样的类可以操纵谷歌地图没有任何帮助。

这是在code,我一直持有至今,一些作品,但有些不是这样。有些我想可能是有用以后。

 包com.MYWEBSITE.www;

进口com.google.android.gms.maps.CameraUpdateFactory;
进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.SupportMapFragment;
进口com.google.android.gms.maps.model.LatLng;
进口android.content.Context;
进口android.location.Criteria;
进口android.location.Location;
进口android.location.LocationManager;
进口android.os.Bundle;
进口android.support.v4.app.FragmentActivity;
进口android.view.Menu;

公共类MainActivity扩展FragmentActivity {
私人GoogleMap的地图;

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main_layout);

    地图=((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap()。
    map.setMyLocationEnabled(真正的);

    // LocationSource A =(LocationSource)getSystemService(Context.LOCATION_SERVICE);
    // LocationManager B =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    //map.setLocationSource(a);

    标准标准=新标准();
    LocationManager locationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    字符串商= locationManager.getBestProvider(标准,FALSE);
    位置位置= locationManager.getLastKnownLocation(供应商);
    双纬度= location.getLatitude();
    双LNG = location.getLongitude();
    经纬度坐标=新的经纬度(纬度,经度);

    //CameraPosition.Builder X = CameraPosition.builder();
    //x.target(coordinate);
    //x.zoom(13);

    //投影PROJ = map.getProjection();
    //点​​对焦= proj.toScreenLocation(坐标);

    //map.animateCamera(CameraUpdateFactory.newLatLng(coordinate));
    map.animateCamera(CameraUpdateFactory.zoomBy(13));
    //map.moveCamera(CameraUpdateFactory.newLatLng(coordinate));


    ////的LatLngBounds边界= mMap.getProjection()getVisibleRegion()的LatLngBounds。;
}
}
 

解决方案
  

您不能动画两件事情(如放大,去我的位置)在一个谷歌地图?

从编码的角度看,你会做他们按顺序:

  CameraUpdate中心=
        CameraUpdateFactory.newLatLng(新经纬度(40.76793169992044,
                                                 -73.98180484771729));
    CameraUpdate变焦= CameraUpdateFactory.zoomTo(15);

    map.moveCamera(中心);
    map.animateCamera(变焦);
 

在这里,我谨相机,再制作动画的摄像头,虽然两者可以是 animateCamera()通话。无论 GoogleMap的这些整合成一个单一的事件,我不能说,因为它的推移太快。 : - )

下面是示例项目从中我把上面的code


对不起,这个答案是有缺陷的。见罗布的回答了这样,才能真正做到这一点的一个镜头,通过创建一个 CameraPosition ,然后创建一个 CameraUpdate 从该 CameraPosition

My question is, does anyone know how to set google maps up, to open up both my location and in a zoomed in view?

Currently, the main view opens up to Africa, all the way zoomed out.

And so I have been searching for days now, and all I can find are:

1) You cannot animate two things (like zoom in and go to my location) in one google map? So if I can figure out how to set the zoom before I set the animate, then this problem would be solved. That tend tend to be the issue, you can change one, but not both.

2) I have found other classes that might be useful, but there is no help on how to set up the code so the class can manipulate the google map.

This is the code I have been holding on to so far, some works, some does not. Some I thought might be useful later on.

package com.MYWEBSITE.www;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity {
private GoogleMap map;  

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);

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

    //LocationSource a = (LocationSource) getSystemService(Context.LOCATION_SERVICE);
    //LocationManager b = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    //map.setLocationSource(a);

    Criteria criteria = new Criteria();
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    String provider = locationManager.getBestProvider(criteria, false);
    Location location = locationManager.getLastKnownLocation(provider);
    double lat =  location.getLatitude();
    double lng = location.getLongitude();
    LatLng coordinate = new LatLng(lat, lng);

    //CameraPosition.Builder x = CameraPosition.builder();
    //x.target(coordinate);
    //x.zoom(13);

    //Projection proj = map.getProjection();
    //Point focus = proj.toScreenLocation(coordinate);

    //map.animateCamera(CameraUpdateFactory.newLatLng(coordinate));
    map.animateCamera(CameraUpdateFactory.zoomBy(13));
    //map.moveCamera(CameraUpdateFactory.newLatLng(coordinate));


    ////LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
}
}

解决方案

You cannot animate two things (like zoom in and go to my location) in one google map?

From a coding standpoint, you would do them sequentially:

    CameraUpdate center=
        CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044,
                                                 -73.98180484771729));
    CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);

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

Here, I move the camera first, then animate the camera, though both could be animateCamera() calls. Whether GoogleMap consolidates these into a single event, I can't say, as it goes by too fast. :-)

Here is the sample project from which I pulled the above code.


Sorry, this answer is flawed. See Rob's answer for a way to truly do this in one shot, by creating a CameraPosition and then creating a CameraUpdate from that CameraPosition.

这篇关于谷歌地图V2 - 设置我的两个位置,并放大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆