Select to view content in your preferred language

How to zoom to a location on a map

1192
4
Jump to solution
08-31-2016 09:42 AM
ThomasSaldana
Emerging Contributor

Hello, 

I keep trying to zoom into a coordinate using the zoomTo(Point centerPt, float factor)  public methoHowever, everytime i run my application, the map starts of the coast of africa. Has anyone had this issue before? Maybe my code is not correct. 

0 Kudos
1 Solution

Accepted Solutions
ShellyGill1
Esri Contributor

Hi Thomas,

In your code, looks like you have the X and Y the wrong way around, assuming that the Point you're creating is supposed to be in a geographical coordinate system - e.g. the coordinates are latitude and longitude, like from GPS position.  The X-axis of the coordinate system is the longitude - for WGS 84 coordinate system, this would be a value from -180 to +180, and the first parameter in point constructor is the x value. The y-axis is latitude, -90 to +90, and the second parameter in the constructor.

I cant tell from your code what coordinate system your map is in - it will be the same coordinate system as that first layer that you add. So as long as that is geographic coordinate system as well, that will work - you need to zoom to a point that is in the same coordinate system as the map.

Hope this helps,

Shelly 

View solution in original post

4 Replies
ThomasSaldana
Emerging Contributor

this is my code:

double xCoordinate = 34.171604;
double yCoordinate = -117.317647;
Point point = new Point(xCoordinate,yCoordinate);


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

    //Retrieve the map and initial extent from XML layout
    mMapView = (MapView) findViewById(R.id.map);
    mMapView.zoomToResolution(point, 15);



    //retrieve layer from server
    mFeatureServiceUrl = this.getResources().getString(R.string.campus);
    mFeatureLayer = new ArcGISFeatureLayer(mFeatureServiceUrl, ArcGISFeatureLayer.MODE.ONDEMAND);
    //add the layer to the mapView
    mMapView.addLayer(mFeatureLayer);
    mGraphicsLayer = new GraphicsLayer();
    mMapView.addLayer(mGraphicsLayer);
0 Kudos
ThomasSaldana
Emerging Contributor

Its 

mMapView.zoomToScale(point, 15);

not
mMapView.zoomToResolution(point, 15);

but it still doesnt work. 

0 Kudos
ShellyGill1
Esri Contributor

Hi Thomas,

In your code, looks like you have the X and Y the wrong way around, assuming that the Point you're creating is supposed to be in a geographical coordinate system - e.g. the coordinates are latitude and longitude, like from GPS position.  The X-axis of the coordinate system is the longitude - for WGS 84 coordinate system, this would be a value from -180 to +180, and the first parameter in point constructor is the x value. The y-axis is latitude, -90 to +90, and the second parameter in the constructor.

I cant tell from your code what coordinate system your map is in - it will be the same coordinate system as that first layer that you add. So as long as that is geographic coordinate system as well, that will work - you need to zoom to a point that is in the same coordinate system as the map.

Hope this helps,

Shelly 

ThomasSaldana
Emerging Contributor

Thank you!!

0 Kudos