---
title: "MKMapView 显示当前位置"
author: "修博龙泉"
date: "2012-12-03T17:14:09Z"
tags: []
categories: ["移动开发"]
slug: "mkmapview"
draft: false
lastmod: "2012-12-07T16:13:49Z"
id: 1740400
url: "https://longquan.iteye.com/blog/1740400"
---

```java

//显示地图
    MKMapView *mapView = [[mkmapview alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    mapView.showsUserLocation = YES;
    [self.view addsubview:mapview];
    
    //显示当前用户经纬度，自动缩放到1000米
    CLLocationManager *locationManager = [[cllocationmanager alloc] init];//创建位置管理器
    locationManager.delegate=self;//设置代理
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别
    locationManager.distanceFilter=10.0f;//设置距离筛选器
    [locationmanager startupdatinglocation];//启动位置管理器
    MKCoordinateSpan theSpan;
    
    //地图的范围 越小越精确
    theSpan.latitudeDelta=0.05;
    theSpan.longitudeDelta=0.05;
    MKCoordinateRegion theRegion;
    theRegion.center=[[locationmanager location] coordinate];
    theRegion.span=theSpan;
    [mapview setregion:theregion];
    [locationmanager release];
    
    [mapview release];


```